[英]Exit code -1073741819 (0xC0000005) with OpenCV
I am trying a really simple OpenCV example in Python, which completely fails to work for me:我正在尝试用 Python 编写一个非常简单的 OpenCV 示例,但它完全不适合我:
import cv2
import matplotlib.pyplot as plt
if __name__ == '__main__':
img1 = plt.imread('../data/input/frame000013.png')
img2 = plt.imread('../data/input/frame000014.png')
img1_gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
sift = cv2.SIFT()
print(sift)
kp = sift.detect(img1_gray, None)
print(kp)
If I try to run it with PyCharm, I get the following error:如果我尝试使用 PyCharm 运行它,则会收到以下错误:
Process finished with exit code -1073741819 (0xC0000005)
If I try to execute it through the terminal, it just does not seem to get past kp = sift.detect(img1_gray, None)
line and does not really get to second print
statement, without providing any error notification whatsoever.如果我尝试通过终端执行它,它似乎没有通过kp = sift.detect(img1_gray, None)
行并且没有真正进入第二个print
语句,而没有提供任何错误通知。
I use: Windows 10, Python 3.8, opencv-python
& opencv-contrib-python
4.4.0.44.我使用:Windows 10、Python 3.8、 opencv-python
和opencv-contrib-python
4.4.0.44。
If you look at the documentation , it should be SIFT_create()
.如果您查看文档,它应该是SIFT_create()
。
sift = cv2.SIFT_create()
print(sift)
kp = sift.detect(img1_gray, None)
But, why are you reading images with plt.imread
?但是,为什么要使用plt.imread
读取图像?
The reason I'm asking, you are converting to the gray-scale using BGR2GRAY
.我问的原因是,您正在使用BGR2GRAY
转换为灰度。 But plt.imread
returns image as RGB
format.但plt.imread
以RGB
格式返回图像。 Therefore, if you are going to use plt.imread
:因此,如果您打算使用plt.imread
:
import cv2
import numpy as np
import matplotlib.pyplot as plt
def rgb2gray(rgb):
return np.dot(rgb[..., :3], [0.2989, 0.5870, 0.1140]).astype(np.uint8)
if __name__ == '__main__':
img1 = plt.imread('../data/input/frame000013.png')
img2 = plt.imread('../data/input/frame000014.png')
img1_gray = rgb2gray(img1)
sift = cv2.SIFT_create()
print(sift)
kp = sift.detect(img1_gray, None)
print(kp)
or if you choose cv2.imread
:或者如果您选择cv2.imread
:
import cv2
import matplotlib.pyplot as plt
if __name__ == '__main__':
img1 = cv2.imread('../data/input/frame000013.png')
img2 = cv2.imread('../data/input/frame000014.png')
img1_gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
sift = cv2.SIFT_create()
print(sift)
kp = sift.detect(img1_gray, None)
print(kp)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.