cv2.imwrite(os.path.join(img_root, 'photo4', filename), erosion) cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:692: error: (-2:Unspecified error) could not find a writer for the specified extension in function 'cv::imwrite_'
时间: 2023-10-16 16:58:40 浏览: 39
这个错误通常是因为你使用的图像格式不支持OpenCV的imwrite函数。请检查你指定的文件扩展名是否正确,例如,如果你指定的文件扩展名为".jpg",则确保你的图像可以保存为JPEG格式。另外,请确保你的OpenCV版本支持你想要保存的图像格式。你可以查看OpenCV文档中的imwrite函数,以了解支持的图像格式和相应的文件扩展名。
相关问题
cv2.imwrite(os.path.join(gray_train_path, filename), img_train) cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:801: error: (-215:Assertion failed) !_img.empty() in function 'cv::imwrite'
这个错误是因为在使用cv2.imwrite()函数时,_img为空或者没有成功读取图片。你可以尝试检查以下几个方面:
1. 检查图片路径是否正确,是否能够成功读取图片。
2. 检查图片是否为空或者损坏,可以尝试用其他工具打开图片进行查看。
3. 检查cv2库是否正常安装,可以尝试重新安装cv2库。
如果以上几个方面都没有问题,你可以尝试更新OpenCV库或者查找其他解决方案。
cv2.imwrite(os.path.join(save_path,prefix), out)
This line of code saves an image in the specified file path and with the specified filename prefix.
- `cv2.imwrite` is a function from the OpenCV library that saves an image to a file.
- `os.path.join(save_path,prefix)` joins the save path and filename prefix to create the full file path where the image will be saved.
- `out` is the image data that will be saved.