could not find a writer for the specified extension in function 'cv::imwrite_'
Question:
I am facing error while defining a function to add border in an image
import cv2
def im_border(path: str, output: str = "output.png"):
im1 = cv2.imread(path)
border = cv2.copyMakeBorder(
im1, 20, 20, 20, 20, cv2.BORDER_CONSTANT, value = [128, 128, 128])
cv2.imwrite(output, border)
return None
im_border(r'C:UsersmanojOneDriveDesktop8a4c4b2b47cdcbb6d359140081f63478.jpg',r'C:UsersmanojOneDriveDesktop')
Why this is giving an error
The error is as follows –
cv2.error: OpenCV(4.5.5) D:aopencv-pythonopencv-pythonopencvmodulesimgcodecssrcloadsave.cpp:730: error: (-2:Unspecified error) could not find a writer for the specified extension in function ‘cv::imwrite_’
Answers:
You are overwriting your default value output.png
with C:UsersmanojOneDriveDesktop
which does not have a valid file ending. Try
C:UsersmanojOneDriveDesktopoutput.png
as output in
im_border(r'C:UsersmanojOneDriveDesktop8a4c4b2b47cdcbb6d359140081f63478.jpg',r'C:UsersmanojOneDriveDesktopoutput.png')
You should provide the correct extension to .imwrite(,)
.
The filename output
must contain a path with the correct extension. (ex : .jpg
, .png
)
Please refer to the previous question.
I am facing error while defining a function to add border in an image
import cv2
def im_border(path: str, output: str = "output.png"):
im1 = cv2.imread(path)
border = cv2.copyMakeBorder(
im1, 20, 20, 20, 20, cv2.BORDER_CONSTANT, value = [128, 128, 128])
cv2.imwrite(output, border)
return None
im_border(r'C:UsersmanojOneDriveDesktop8a4c4b2b47cdcbb6d359140081f63478.jpg',r'C:UsersmanojOneDriveDesktop')
Why this is giving an error
The error is as follows –
cv2.error: OpenCV(4.5.5) D:aopencv-pythonopencv-pythonopencvmodulesimgcodecssrcloadsave.cpp:730: error: (-2:Unspecified error) could not find a writer for the specified extension in function ‘cv::imwrite_’
You are overwriting your default value output.png
with C:UsersmanojOneDriveDesktop
which does not have a valid file ending. Try
C:UsersmanojOneDriveDesktopoutput.png
as output in
im_border(r'C:UsersmanojOneDriveDesktop8a4c4b2b47cdcbb6d359140081f63478.jpg',r'C:UsersmanojOneDriveDesktopoutput.png')
You should provide the correct extension to .imwrite(,)
.
The filename output
must contain a path with the correct extension. (ex : .jpg
, .png
)
Please refer to the previous question.