Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在opencv python中将输出帧组合在一起?_Python_Opencv_Image Processing - Fatal编程技术网

如何在opencv python中将输出帧组合在一起?

如何在opencv python中将输出帧组合在一起?,python,opencv,image-processing,Python,Opencv,Image Processing,我正在处理输入图像。我有一系列的步骤要在图像上完成,所有的结果一个接一个地出现在不同的窗口中。我真的需要将这些结果组合起来,以便将其显示为一个视频,具有与不同帧相同的输入图像,并在帧上显示每个操作的结果 例如,我有outpu1、output2、output3和output4,这是当前在4个单独窗口中显示的cv2.imshow()的结果。我需要将这些结果合并到一个窗口中,像视频一样显示,每个结果一个接一个地出现。有可能吗?有人能给我一个主意吗?任何帮助都将不胜感激。谢谢大家! 所以我假设你现在正在

我正在处理输入图像。我有一系列的步骤要在图像上完成,所有的结果一个接一个地出现在不同的窗口中。我真的需要将这些结果组合起来,以便将其显示为一个视频,具有与不同帧相同的输入图像,并在帧上显示每个操作的结果


例如,我有outpu1、output2、output3和output4,这是当前在4个单独窗口中显示的cv2.imshow()的结果。我需要将这些结果合并到一个窗口中,像视频一样显示,每个结果一个接一个地出现。有可能吗?有人能给我一个主意吗?任何帮助都将不胜感激。谢谢大家!

所以我假设你现在正在做类似的事情来显示你的图像

cv2.imshow("preview", output1)
cv2.waitKey(0)
传递给waitKey函数的参数是帧在名为preview的窗口中应显示的毫秒数。如果该值为0,则将无限期显示。 现在,如果有四帧输出1。。输出4您可以这样显示它们

cv2.imshow("preview", output1)
cv2.waitKey(1000)
cv2.imshow("preview", output2)
cv2.waitKey(1000)
cv2.imshow("preview", output3)
cv2.waitKey(1000)
cv2.imshow("preview", output4)
cv2.waitKey(1000)

它的作用是显示output1,等待1秒(1000毫秒),然后显示output2,依此类推。我建议您将它们放在一个列表中,并在循环中运行,而不是重复代码。

您可以使用
np.stack
查看图像

您可以使用以下功能查看合并图像

def stackImages(scale, imgArray):
  rows = len(imgArray)
  cols = len(imgArray[0])
  rowsAvailable = isinstance(imgArray[0], list)
  width = imgArray[0][0].shape[1]
  height = imgArray[0][0].shape[0]
  if rowsAvailable:
    for x in range(0, rows):
      for y in range(0, cols):
        if imgArray[x][y].shape[:2] == imgArray[0][0].shape[:2]:
          imgArray[x][y] = cv2.resize(imgArray[x][y], (0, 0), None, scale,
                                      scale)
        else:
          imgArray[x][y] = cv2.resize(imgArray[x][y], (
            imgArray[0][0].shape[1], imgArray[0][0].shape[0]),
                                      None, scale, scale)
        # if len(imgArray[x][y].shape) == 2: imgArray[x][y] = cv2.cvtColor(
        #     imgArray[x][y], cv2.COLOR_GRAY2BGR)
    imageBlank = np.zeros((height, width, 3), np.uint8)
    hor = [imageBlank] * rows
    hor_con = [imageBlank] * rows
    for x in range(0, rows):
      hor[x] = np.hstack(imgArray[x])
    ver = np.vstack(hor)
  else:
    for x in range(0, rows):
      if imgArray[x].shape[:2] == imgArray[0].shape[:2]:
        imgArray[x] = cv2.resize(imgArray[x], (0, 0), None, scale, scale)
      else:
        imgArray[x] = cv2.resize(imgArray[x],
                                 (imgArray[0].shape[1], imgArray[0].shape[0]),
                                 None, scale,
                                 scale)
      # if len(imgArray[x].shape) == 2: imgArray[x] = cv2.cvtColor(imgArray[x],
      #                                                            cv2.COLOR_GRAY2BGR)
    hor = np.hstack(imgArray)
    ver = hor
  return ver


将图像放入
列表
中,并将其传递给上面定义的
stackImages
函数

这是否回答了您的问题?不,我不是在寻找你提到的答案中所示的并排帧的连接。你是说一个屏幕中有4个屏幕?如果你继续使用相同的窗口标题,图像将重复使用相同的窗口。。。i、 e.不会出现新窗口。