51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

在Python中读取位图图像时崩溃。

英文:

Crash when reading bit map image in python

问题 {#heading}

使用以下代码块,我正在尝试读取并存储一个BMP图像,以便使用匹配算法进行图像处理。

print("starting read image function")
fimage = glob.glob("test.bmp")
incomingFingerprint = cv2.imread(fimage)
cv2.imwrite(fimage.replace('.bmp', '.jpg'), incomingFingerprint)

我发现我的代码崩溃,并在终端中打印了以下行:

进程以退出码 -1073740791 (0xC0000409) 结束

我想成功地读取并将图像存储在一个变量中,然后应用一些图像处理算法。 英文:

Using the following code block, I am trying to read and store a bmp image in order to make some image processing using a matching algorithm.

  print("starting read image function")
    fimage = glob.glob("test.bmp")
    incomingFingerprint = cv2.imread(fimage)
    cv2.imwrite(fimage.replace('.bmp', '.jpg'), incomingFingerprint)

I got my code crashed and printed this line in the terminal:

Process finished with exit code -1073740791 (0xC0000409)

I want to successfully read and store an image in a variable and then apply some image processing algorithms.

答案1 {#1}

得分: 0

你错误地使用了 glob --- 它在输出时会给你一个列表。相反,只需将图像名称传递给 imreadimwrite 函数:

import cv2

incoming_fingerprint = cv2.imread('test.bmp')
cv2.imwrite('test.jpg', incoming_fingerprint)

英文:

You're incorrectly using glob --- it gives you a list on output. Instead, simply pass image name to the imread and imwrite functions:

import cv2
`incoming_fingerprint = cv2.imread('test.bmp')
cv2.imwrite('test.jpg', incoming_fingerprint)
`


赞(9)
未经允许不得转载:工具盒子 » 在Python中读取位图图像时崩溃。