TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'
You cannot use operand +
on a PosixPath
object. Instead, you should use /
when dealing with the pathlib
library:
# before
cv2.imwrite(path + "/" + "photo.png", img)
# after
cv2.imwrite(path / "photo.png", img)
If you look through your type error, it's actually because you're trying to use the +
operator on a PosixPath
type and a str
. You'll need to convert the PosixPath
to a string before you can use the imwrite
.
Maybe try:
cv2.imwrite(str(path) + "/" + "photo.png", img)
Alternatively, use the proper concatenation as described in the pathlib docs.
First convert the PosixPath object (path
) to string:
str(path) + "/" + "photo.png"