[英]cv2 Stitcher and Thread Behaving Strange
我正在尝试在 RPi 4 8GB RAM 上使用来自 cv2 的 Stitcher 缝合 16 张图像,当我将它与 Thread 一起使用时它不起作用下面是 python 脚本:
import cv2
import numpy as np
import os
import time
from threading import Thread
cv2.ocl.setUseOpenCL(True)
global images
images = []
imgreg_path = "/home/pi/shared/"
class t1:
def __init__(self):
self._running = True
def terminate(self):
self._running = False
def run(self):
global images
global stitcher
stitcher = cv2.Stitcher_create(mode=1)
print("Thread 1 running")
print(len(images))
(status, stitched) = stitcher.stitch(images)
if status == 0:
cv2.imwrite('/home/pi/Desktop/stitched.jpg', stitched)
print('Thread 1 Stitched')
images = []
else:
print('Thread 1 Not Stitched')
images = []
for i in range(2,18):
curImg = cv2.imread(imgreg_path+"image"+str(i)+".jpg")
images.append(curImg)
print(len(images))
task1 = t1()
thrd1 = Thread(target=task1.run)
thrd1.start()
while True:
time.sleep(5)
和OUTPUT
>>> %Run testsew.py
16
Thread 1 running
16
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/Desktop/testsew.py", line 24, in run
(status, stitched) = stitcher.stitch(images)
cv2.error: OpenCV(4.1.0) /home/pi/opencv-python/opencv/modules/core/src/umatrix.cpp:454: error: (-215:Assertion failed) u != 0 in function 'create'
然而它在没有线程的情况下完美地工作,下面是 python 脚本:
import cv2
import numpy as np
import os
import time
from threading import Thread
cv2.ocl.setUseOpenCL(True)
imgreg_path = "/home/pi/shared/"
stitcher = cv2.Stitcher_create(mode=1)
images = []
print("Running")
for i in range(2,18):
curImg = cv2.imread(imgreg_path+"image"+str(i)+".jpg")
images.append(curImg)
print(len(images))
(status, stitched) = stitcher.stitch(images)
if status == 0:
cv2.imwrite('/home/pi/Desktop/stitched.jpg', stitched)
print('Stitched')
images = []
else:
print('Not Stitched')
images = []
和OUTPUT
>>> %Run testsew_read.py
Running
16
Stitched
任何帮助都可以实现缝合和穿线。 谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.