Это мой код для определения круга/шаров. Я хочу обнаружить футбольный мяч с камеры Pi. (футбольный мяч может быть любого цвета.) У меня возникают проблемы с некоторыми PiCameraValueError. Что не так с этим кодом. Я использую Raspberry Pi 2, Python2 и OpenCV.PiCameraValueError: неправильная длина буфера для разрешения 1920x1080
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import sys
import imutils
import cv2.cv as cv
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
rawCapture = PiRGBArray(camera)
# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr"):
# grab the raw NumPy array representing the image, then initialize the timestamp
# and occupied/unoccupied text
image = frame.array
img = cv2.medianBlur(image, 5)
imgg = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
cimg = cv2.cvtColor(imgg, cv2.COLOR_GRAY2BGR)
imgg = cv2.blur(imgg, (3,3))
#imgg = cv2.dilate(imgg, np.ones((5, 5)))
#imgg = cv2.GaussianBlur(imgg,(5,5),0)
circles = cv2.HoughCircles(imgg, cv.CV_HOUGH_GRADIENT, 1, 20, param1=100, param2=40, minRadius=5, maxRadius=90)
cv2.imshow("cimg", imgg)
key = cv2.waitKey(1)
if key & 0xFF == ord('q'):
break
if circles is None:
continue
print circles
#circles = np.uint16(np.around(circles))
for i in circles[0,:]:
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),1) # draw the outer circle
#cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3) # draw the center of the circle
cv2.imshow("Filtered", cimg)
cv2.destroyWindow("cimg")
cv2.destroyAllWindows()
Спасибо. У меня возникают проблемы с этим кодом для обнаружения шара. У меня разные футбольные мячи. –