简体   繁体   English

Python的OpenCV cv2.imread总是返回None而cvFeatDetector崩溃了python

[英]Python's OpenCV cv2.imread always returns None and cvFeatDetector crashes python

I'm getting my feet wet with opencv in python, and I figure a good place to start is loading an image. 我正在用python中的opencv弄湿我的脚,我认为一个好的起点是加载一个图像。

I've built opencv on my system, and have the python bindings and opencv dlls in the directory tpl/opencv, which is relative to my project. 我在我的系统上构建了opencv,并在目录tpl / opencv中有python绑定和opencv dll,这与我的项目有关。

Here is some code that demonstrates the problem: 以下是一些演示此问题的代码:

from tpl.opencv import cv2
from tpl.opencv.cv2 import cv
from PIL import Image

pil_img =  Image.open('C:/test_file.jpg') #Read a temp file, the input is actually a computed image chip
tmpname =  'C:/tmp.png' 
pil_img.save(tmpname,'PNG') # Write the image chip to disk

im  = cv.LoadImage(tmpname) # This seems to work
im2 = cv2.imread(tmpname)   # This always returns None

There is no error message, im2 is just always None. 没有错误消息,im2总是无。 Could I have messed something up with the way I'm importing opencv? 我可以用我导入opencv的方式搞砸了吗? Is there a simple workaround? 有一个简单的解决方法吗?

When I create 当我创造

 cvFeatDetector  = cv2.FeatureDetector_create("MSER")

I get , so that part of cv2 seems to work 我知道,所以cv2的一部分似乎有效


As a workaround I just loaded the image with numpy 作为一种解决方法,我只是用numpy加载图像

        im2 = numpy.imread(inname)
        im  = cv2.cvtColor(im2, cv2.COLOR_BGR2GRAY) # This works. I was able to imshow it too
        cvFeatDetector  = cv2.FeatureDetector_create("MSER") # Seems to produce a valid object
        cvFeatExtractor = cv2.DescriptorExtractor_create("SIFT") # Seems to produce a valid object
        kpts         = cvFeatDetector.detect(im)  # Crashes python

I find this very odd, because cv2.cvtColor converts the image successfully to grayscale. 我发现这很奇怪,因为cv2.cvtColor将图像成功转换为灰度。 So some cv2 functions do work, and others fail to varying degrees. 所以一些cv2函数确实有效,而其他函数则不同程度。


Edit. 编辑。 I fixed this by installing the released 2.4 of opencv. 我通过安装opencv的2.4版来解决这个问题。

As stated in the edited question, this is a bug that was fixed in a newer release of v2.4 of OpenCV. 如编辑问题中所述,这是一个在OpenCV v2.4的较新版本中修复的错误。 No further info seems to be currently available about the bug fix. 目前没有关于错误修复的进一步信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM