gpt4 book ai didi

python - cv2.SIFT() 导致段错误

转载 作者:行者123 更新时间:2023-12-05 00:55:35 26 4
gpt4 key购买 nike

我在树莓派 3b 上使用 opencv 4.5.0-pre 和 python 3.7.3。我正在尝试使用 SIFT 为图像拼接找到最匹配的特征。我使用本指南从源代码构建了 opencv https://www.pyimagesearch.com/2019/09/16/install-opencv-4-on-raspberry-pi-4-and-raspbian-buster/ .

import cv2

img1 = cv2.imread('image1.jpg')
gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
img2 = cv2.imread('image2.jpg')
gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

sift = cv2.SIFT()
kp1, des1 = sift.detectAndCompute(gray1, None)
kp2, des2 = sift.detectAndCompute(gray2, None)

在运行脚本时会抛出此错误:

/bin/bash: line 1:  1101 Segmentation fault      python3 stitch_imgs.py

shell returned 139

Press ENTER or type command to continue

我已经尝试按照@Ahx 的建议使用 cv2.xfeatures2d.SIFT_create()。但这对我也不起作用。我得到以下输出:

[ WARN:0 ] global /home/pi/opencv_contrib/modules/xfeatures2d/misc/python/shadow_shift.hpp
(15) SIFT_create DEPRECATED: cv.xfeatures2d.SIFT_create() is deprecated due to
the main repository. https://github.com/opencv/opencv/issues/16736

Killed

有人知道我该如何解决这个问题吗?

谢谢

最佳答案

来自 documentation1 , 和 documentation2你需要声明 SIFT 如下:

对于 opencv-4.0.0

sift = cv2.xfeatures2d.SIFT_create()

对于 opencv-4.5-0-pre

sift = cv2.SIFT_create()

对于opencv-4.0.0代码:


import cv2

img1 = cv2.imread('img1.jpg')
gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
img2 = cv2.imread('img2.jpg')
gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

sift = cv2.xfeatures2d.SIFT_create()
kp1, des1 = sift.detectAndCompute(gray1, None)
kp2, des2 = sift.detectAndCompute(gray2, None)

对于opencv-4.5.0-pre 代码:

import cv2

img1 = cv2.imread('img1.jpg')
gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
img2 = cv2.imread('img2.jpg')
gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

sift = cv2.SIFT_create()
kp1, des1 = sift.detectAndCompute(gray1, None)
kp2, des2 = sift.detectAndCompute(gray2, None)

关于python - cv2.SIFT() 导致段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63949074/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com