参考:http://www.voidcn.com/article/p-dusgpwtd-bpv.html
cv2.imread(absolute_path) 有时会报错:
Corrupt JPEG data: 2 extraneous bytes before marker 0xd9
c++的解决方法:
Corrupt JPEG data: 36 extraneous bytes before marker 0xd9,opencv获取imread报错方法_lcj1105的专栏-CSDN博客
‘Premature end of JPEG file’是使用cv2(python版的opencv)读取图片时出现的警告,警告代码位于libjpeg中,
JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
184 JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
185 JMESSAGE(JWRN_MUST_RESYNC,
186 "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
"Warning: unknown JFIF revision number %d.%02d")
184 JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
185 JMESSAGE(JWRN_MUST_RESYNC,
186 "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
具体链接为https://github.com/opencv/opencv/search?utf8=%E2%9C%93&q=JWRN_JPEG_EOF
在调试定位图像时,确实发现图像有破损。
二、解决方法
为了让python代码捕捉异常,程序修改如下:
try:
img = Image.open(absolute_path)
except IOError:
print(absolute_path)
try:
img= np.asarray(img)
except :
print('corrupt img',absolute_path)
在OpenCV中使用imread()加载图像时,如何捕获损坏的JPEG? - 主函数编程网
absolute_path为文件的完整路径(绝对路径),即文件路径+文件名
参考:
这个推荐方法是opencv重新编译一下:
corrupt JPEG data: # extraneous bytes before marker 0x## · Issue #9477 · opencv/opencv · GitHub
数据被破坏了,
Qt加载JPEG出现Corrupt JPEG data: 1 extraneous bytes before marker 0xd9解决办法_swz5637的博客-CSDN博客
出现这个问题主要是长度问题。
添加长度以后就OK了。如以下:
QImage imgFace;
imgFace.loadFromData((uchar*)deDF,size);