【发布时间】:2023-04-05 17:05:01
【问题描述】:
我正在对多个图像执行对象检测,这些图像是从覆盖更广视角的多个摄像头捕获的。由于我想防止多次计算同一个对象,我想知道是否可以计算拼接图像上对象相对于源图像坐标的坐标。这样,如果源图像上多个对象的坐标在拼接图像上大致相等,我将只计算一次对象。以下是图像拼接示例:拼接后的图像由 3 个重叠图像组成;在第一张和第二张图像上,检测到同一个物体,应该只计算一次。
这是我为拼接编写的示例代码:
import cv2
import imutils
from videostream import VideoStreamWidget
index = 0
arr = []
stitcher = cv2.createStitcher() if imutils.is_cv3() else cv2.Stitcher_create()
cams_test = 200
for i in range(cams_test):
cap = cv2.VideoCapture(i)
test, frame = cap.read()
if test:
print("i : " + str(i) + " /// result: " + str(test))
arr.append(i)
video_captures = [VideoStreamWidget(idx) for idx in arr]
images_to_stitch = []
for i, video_stream_widget in enumerate(video_captures):
try:
if video_stream_widget.frame is not None:
cv2.imshow('Cam {}'.format(i), cv2.resize(video_stream_widget.frame, (0, 0), fx=0.25, fy=0.25))
images_to_stitch.append(video_stream_widget.frame)
except Exception as e:
print(e)
pass
try:
(status, stitched) = stitcher.stitch(images_to_stitch)
if status == 0:
cv2.imshow("Stitched", cv2.resize(stitched, (0, 0), fx=0.1, fy=0.25))
except:
print("stitching failed")
print(status)
【问题讨论】:
-
它是如何缝合的?你能在这里添加一些最小的可重现代码吗?
-
你可以从
cv2.match_template()开始
标签: python opencv computer-vision