繁体   English   中英

opencv 未捕获所有帧

[英]opencv not capturing all frames

我试图在整个视频中检测球的 position。 一开始,我裁剪视频,因为我的原始剪辑顶部有一些随机的东西。 我不知道为什么,但程序并没有捕捉到所有的帧——它在第一帧之后就停止了。 我在另一台电脑上试了一下,效果很好。 我不知道出了什么问题。

import cv2
import numpy as np

# Open the video
cap = cv2.VideoCapture('video-4.mp4')

while(1):
    success, frame = cap.read()
    # Take each frame
    if success:
        crop_img = frame[100:3000, 100:3000].copy()
        gray = cv2.cvtColor(crop_img, cv2.COLOR_BGR2GRAY)
        circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, dp=1.5, minDist=505,param1=75, param2=30, minRadius=8, maxRadius=10)
        # ensure at least some circles were found
        if circles is not None:
            # convert the (x, y) coordinates and radius of the circles to integers
            circles = np.round(circles[0, :]).astype("int")
            # loop over the (x, y) coordinates and radius of the circles
            for (x, y, r) in circles:
                print(x,y,r)
                # draw the circle in the output image, then draw a rectangle
                # corresponding to the center of the circle
                cv2.circle(crop_img, (x, y), r, (0, 255, 0), 4)
                cv2.rectangle(crop_img, (x - 5, y - 5),
                            (x + 5, y + 5), (0, 128, 255), -1)
        cv2.namedWindow("hi", cv2.WINDOW_NORMAL)
        cv2.imshow('hi', crop_img)
        cv2.waitKey(0)
    else:
        break
    
cv2.destroyAllWindows()

在此处输入图像描述

  • 您正在使用y而不初始化它。

  • 您正在使用cv2.CAP_PROP_FRAME_WIDTH就好像它是宽度但它不是。 告诉OpenCV function 返回什么只是一个“定义”

  • 当您应该使用高度作为第一个索引时,您首先按宽度索引frame

暂无
暂无

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

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