我试图分析目录中的一组图像,但只有一个图像起作用。所有图像的大小大致相同(3MB),并且来自相同的原始图像。所有这些都可以在GIMP和照片中查看,但cv2.imshow仅适用于slice_0_15.jpg
这里发生了什么?
使用Python版本3.8.3、OpenCV版本4.2.0
for file in os.listdir("scanned_extrudate"): #go through all 18 slices in the directory
print("Analyzing file " + str(file))
image = cv2.imread(file)
if image is None:
print("Error: no image selected")
else:
rows,cols,_ = image.shape #dimensions of image (eg 200x300)
print("Image: " + str(rows) + " rows, " + str(cols) + " columns")
输出:
Analyzing file slice_0_0.jpg
Error: no image selected
Analyzing file slice_0_1.jpg
Error: no image selected
Analyzing file slice_0_10.jpg
Error: no image selected
Analyzing file slice_0_11.jpg
Error: no image selected
Analyzing file slice_0_12.jpg
Error: no image selected
Analyzing file slice_0_13.jpg
Error: no image selected
Analyzing file slice_0_14.jpg
Error: no image selected
Analyzing file slice_0_15.jpg
Image: 19935 rows, 928 columns
Analyzing file slice_0_16.jpg
Error: no image selected
Analyzing file slice_0_17.jpg
Error: no image selected
Analyzing file slice_0_2.jpg
Error: no image selected
Analyzing file slice_0_3.jpg
Error: no image selected
Analyzing file slice_0_4.jpg
Error: no image selected
Analyzing file slice_0_5.jpg
Error: no image selected
Analyzing file slice_0_6.jpg
Error: no image selected
Analyzing file slice_0_7.jpg
Error: no image selected
Analyzing file slice_0_8.jpg
Error: no image selected
Analyzing file slice_0_9.jpg
Error: no image selected
当我在终端中键入“file*”时,所有图像的结果都相同:(唯一的区别是尺寸)
slice_0_0.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 2400x2400, segment length 16, Exif Standard: [TIFF image data, little-endian, direntries=7, xresolution=98, yresolution=106, resolutionunit=2, software=GIMP 2.10.14, datetime=2020:07:10 13:34:33], progressive, precision 8, 1088x19935, frames 1
这是因为您没有读取扫描的挤出物文件中的图像。您看到的图像看起来是正确的目录,但您试图在错误的目录中读取。这将解决您的问题:
试试这个:
相关问题 更多 >
编程相关推荐