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

huangapple go评论102阅读模式
英文:

Crash when reading bit map image in python

问题

使用以下代码块,我正在尝试读取并存储一个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

得分: 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)

huangapple
  • 本文由 发表于 2023年8月10日 16:38:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76873987.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定