无法广播形状的输入数组

时间:2019-09-10 12:09:09

标签: python-3.x

我正在尝试从.mp4文件中读取视频。

我遇到错误:   显示中的文件“ demoprotoupsilon.py”,第271行     播放视频(年龄)   PlayVideo中的文件“ demoprotoupsilon.py”,第217行     bg [y1:y2,x1:x2] =帧 ValueError:无法将输入数组从形状(360,480,3)广播到形状(360,480,4)

源代码:

    def PlayVideo(age):
   print("toto");
   birthyear = datetime.datetime.now().year - age
   videoFilePath = f"media/video/decades/{int(round(birthyear, -1))}.mp4"
   print(videoFilePath)
   vid = cv2.VideoCapture(videoFilePath)
   bg = GetDisplayImgContent()
   if vid.isOpened():
      print("in vidopen")
      while vid.isOpened():
         print("in while")
         ret, frame = vid.read()
         if ret:
            print("img OK")
            #frame = cv2.bitwise_and( frame, frame)
            #cv2.add(bg, frame)
            origVidImgHeight, origVidImgWidth = frame.shape[:2]
            print(frame.shape)
            #orig_mask = frame[:,:,2]
            #orig_mask_inv = cv2.bitwise_not(orig_mask)


            xVidPosition = int((screenW / 3)*2)
            yVidPosition = int((screenH / 4)*3)

            x1 = int(xVidPosition - (origVidImgWidth / 2))
            x2 = int(xVidPosition + (origVidImgWidth / 2))
            y1 = int(yVidPosition - (origVidImgHeight / 2))
            y2 = int(yVidPosition + (origVidImgHeight / 2))

            roi = bg[y1:y2, x1:x2]
            #roi_bg = cv2.bitwise_and( roi, roi, mask = orig_mask_inv)
            #roi_fg = cv2.bitwise_and( frame, frame, mask = orig_mask)

            #dst = cv2.add(roi_bg, roi_fg)

            bg[y1:y2, x1:x2] = frame
            SetDisplayImg(bg, "")
         else:
            break
      vid.release()
      cv2.destroyAllWindows()

请问有什么想法吗?

0 个答案:

没有答案