尝试使用 findContours() 但不断收到 cpp:197 错误(-210: 不支持的格式或格式组合)
我在其他文件中使用了相同的格式,效果很好。不知道为什么它在这里不起作用。
完整错误:
Traceback (most recent call last):
File "C:/Users/FreddyMac/PycharmProjects/TestProj/ballTrackingAbsDiff.py", line 33, in <module>
cnts = cv2.findContours(th1, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-cff9bdsm\opencv\modules\imgproc\src\contours.cpp:197: error: (-210:Unsupported format or combination of formats) [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function 'cvStartFindContours_Impl'
Run Code Online (Sandbox Code Playgroud)
我检查了图像的类型,它是正确的“uint8”类型。
请参阅下面的代码。
import cv2
import imutils
vs = cv2.VideoCapture('ballsFlying.MP4')
while True:
# read frame1, resize and convert to grayscale
ret, frame1 = vs.read()
if frame1 is None:
break
frame1 …Run Code Online (Sandbox Code Playgroud) 只是寻找一些关于如何解决不同颜色球的高尔夫球跟踪问题的建议。
我探索过使用absdiff()来获取帧之间的差异来跟踪球,但它也可以获取球员和球杆的运动。另外,使用 HSV 来拾取特定颜色的球,但我希望能够拾取大多数颜色(白色、黄色、橙色、蓝色)。谢谢。