简体   繁体   English

OpenCV是否同时运行两个SIFT实例detectAndCompute?

[英]Is OpenCV running two instances of SIFT detectAndCompute concurrently?

I can get SIFT keypoints and descriptors from two, seperate, large images (~2GB) when I run sift.detectAndCompute from the command line. 从命令行运行sift.detectAndCompute时,我可以从两个单独的大图像(约2GB)中获取SIFT关键点和描述符。 I run it on one image, wait a very long time, but eventually get the keypoints and descriptors. 我在一张图像上运行它,等待了很长时间,但最终获得了关键点和描述符。 Then I repeat for the second image, and again it takes a long time, but I DO eventually get my keypoints and descriptors. 然后,我重复第二张图像,这又花费了很长时间,但最终我确实得到了关键点和描述符。 Here are the two lines I run from the IPython console in Spyder, which I am running on my machine with 32 GB of RAM. 这是我从Spyder的IPython控制台运行的两行代码,它们在具有32 GB RAM的计算机上运行。 (MAX_MATCHES = 50000 in the code below): (以下代码中的MAX_MATCHES = 50000):

sift = cv2.xfeatures2d.SIFT_create(MAX_MATCHES)
keypoints, descriptors = sift.detectAndCompute(imgGray, None)

This takes 10 minutes to finish, but it does finish. 这需要10分钟才能完成,但确实可以完成。 Next, I run this: 接下来,我运行此命令:

keypoints2, descriptors2 = sift.detectAndCompute(refimgGray, None)

When done, keypoints and keypoints2 DO contain 50000 keypoint objects. 完成后,关键点和关键点2确实包含50000个关键点对象。

However, if I run my script, which calls a function that uses sift.detectAndCompute and returns keypoints and descriptors, the process takes a long time, uses 100% of my memory and ~95% of my disk BW and then fails with this traceback: 但是,如果我运行脚本,该脚本调用使用sift.detectAndCompute的函数并返回关键点和描述符,则该过程将花费很长时间,使用100%的内存和〜95%的磁盘带宽,然后由于该回溯而失败:

runfile('C:/AV GIS/python scripts/img_align_w_geo_w_mask_refactor_ret_1.py', wdir='C:/AV GIS/python scripts')
Reading reference image :  C:\Users\kellett\Downloads\3074_transparent_mosaic_group1.tif
xfrm for image =  (584505.1165100001, 0.027370000000000002, 0.0, 4559649.608440001, 0.0, -0.027370000000000002)
Reading image to align :  C:\Users\kellett\Downloads\3071_transparent_mosaic_group1.tif
xfrm for image =  (584499.92168, 0.02791, 0.0, 4559648.80372, 0.0, -0.02791)
Traceback (most recent call last):

File "<ipython-input-75-571660ddab7f>", line 1, in <module>
    runfile('C:/AV GIS/python scripts/img_align_w_geo_w_mask_refactor_ret_1.py', wdir='C:/AV GIS/python scripts')

File "C:\Users\kellett\AppData\Local\Continuum\anaconda3\envs\testgdal\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
    execfile(filename, namespace)

File "C:\Users\kellett\AppData\Local\Continuum\anaconda3\envs\testgdal\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/AV GIS/python scripts/img_align_w_geo_w_mask_refactor_ret_1.py", line 445, in <module>
    matches = find_matches(refKP, refDesc, imgKP, imgDesc)

File "C:/AV GIS/python scripts/img_align_w_geo_w_mask_refactor_ret_1.py", line 301, in find_matches
    matches = matcher.match(dsc1, dsc2)

error: C:\ci\opencv_1512688052760\work\modules\core\src\stat.cpp:4024: error: (-215) (type == 0 && dtype == 4) || dtype == 5 in function cv::batchDistance

The function is simply called once for each image thusly: 因此,只需为每个图像调用一次该函数:

print("Reading image to align : ", imFilename);  
img, imgGray, imgEdgmask, imgXfrm, imgGeoInfo = read_ortho4align(imFilename)

refKP, refDesc = extractKeypoints(refimgGray, refEdgmask)
imgKP, imgDesc = extractKeypoints(imgGray, imgEdgmask)

HERE IS MY QUESTION (sorry for shouting): Do you think Python tries to run the two lines above concurrently in some way? 这是我的问题(很抱歉大喊大叫):您是否认为Python尝试以某种方式同时运行以上两行? If so, how can I force it to run serially? 如果是这样,我如何强制它连续运行? If not, do you have any idea why the two keypoint detections would work individually, but not when they come one after another in a script? 如果不是,您是否知道为什么两个关键点检测将单独起作用,而在脚本中一个接一个地出现时却不起作用?

One more clue - I put in a statement to see if the script proceeds to the second detectAndCompute statement before it fails, and it does. 另一个线索-我放入一条语句,以查看脚本是否在失败之前继续执行第二个detectAndCompute语句,并且确实如此。 (I just put a print statement in between the two.) (我只是在两者之间添加了打印语句。)

My error was coming later in my script where I was finding matches. 我的错误稍后在我找到匹配项的脚本中出现。

I have no reason to believe the two SIFT keypoint finding processes are occurring at the same time. 我没有理由相信两个SIFT关键点查找过程是同时发生的。

I downsampled the images I was searching for SIFT keypoints and was able to iterate my troubleshooting more quickly and found my error. 我对正在搜索SIFT关键点的图像进行了下采样,从而能够更快地迭代故障排除并发现错误。

I will look at my error more closely next time before asking a question. 下次再问问题之前,我将更仔细地研究我的错误。

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

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