In dem folgenden Code habe ich versucht herauszufinden, ob ein Objekt grün ist, und zeichnet eine Kontur um es herum. Mit diesen Informationen möchte ich auch die Ecken der Form finden und sie erregen, aber ich erhalte einen Fehler in Bezug auf die konvexe Funktion, die ich im Code nicht verwendet habe. Ich habe Python 3 und OpenCV 3.2.0 < /p>
Der von mir geschriebene Code verwendetTraceback (most recent call last):
File "/home/pi/Desktop/SelfDrivingCar/code/picamsense2.py", line 29, in
points = cv2.minAreaRect(contour)
error: /home/pi/opencv/opencv-3.2.0/modules/imgproc/src/convhull.cpp:136: error: (-215) total >= 0 && (depth == CV_32F || depth == CV_32S) in function convexHull
< /code>
Hier ist mein Code < /p>
from picamera import PiCamera
import time
import cv2
import numpy as np
camera = PiCamera()
camera.start_preview()
time.sleep(5)
camera.capture('/home/pi/Desktop/piImage/image.jpg')
camera.stop_preview()
img = cv2.imread('/home/pi/Desktop/piImage/image.jpg', 1)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
lower = np.array([46, 100, 100])
upper = np.array([86, 255, 255])
mask = cv2.inRange (hsv, lower, upper)
blur = cv2.GaussianBlur(mask, (7,5),0 )
erosion =cv2.erode(blur, (5,5), iterations = 3)
contour =np.array( cv2.findContours(erosion, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)[1])
cv2.drawContours(img, contour, -1, (0,255,0), 3)
for cnt in contour:
approx = cv2.approxPolyDP(cnt, 0.04*cv2.arcLength(cnt, True), True)
if len (approx)== 3:
print "triangle"
elif len (approx) == 4 :
print "quadrilateral"
elif len(approx) > 4:
print "circle"
points = cv2.minAreaRect(contour)
points = cv2.boxPoints(points)
points = np.int0(points)
for p in points :
pt = (p[0],p[1])
print pt
print points
cv2.imshow('eroded', blur)
cv2.imshow('original', img)
while (1):
k = cv2.waitKey(0)
if(k == 27):
break
cv2.destroyAllWindows()
< /code>
Ich habe jetzt versucht, nach einem Fix einige Zeit zu suchen.>
Fehler mit CV2.Minarearect gibt mir einen Fehler in Bezug auf die konvexe Rumpffunktion, die ich nicht verwendet habe ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post