Étape 20 : OpenCV : flotteurs stupides
#////////CV Dawing//////////////////////////////#Target circle cv2.circle(frame, (tX, tY), 10, (0, 0, 255), thickness=-1) #ser.write(botXY)#Background for text. cv2.rectangle(frame, (18,2), (170,160), (255,255,255), -1) #Target angle. cv2.line(frame, (tX,tY), (cxAvg,cyAvg),(0,255,0), 1) #Bot's X and Y is written to image cv2.putText(frame,str(cx)+" cx, "+str(cy)+" cy",(20,20),cv2.FONT_HERSHEY_COMPLEX_SMALL,.7,(0,0,0)) #Bot's X and Y averages are written to image cv2.putText(frame,str(cxAvg)+" cxA, "+str(cyAvg)+" cyA",(20,40),cv2.FONT_HERSHEY_COMPLEX_SMALL,.7,(0,0,0)) #"Ok" is written to the screen if the X&Y are close to X&Y Avg for several iterations. cv2.putText(frame,stringXOk,(20,60),cv2.FONT_HERSHEY_COMPLEX_SMALL,.7,(0,0,0)) cv2.putText(frame,stringYOk,(20,80),cv2.FONT_HERSHEY_COMPLEX_SMALL,.7,(0,0,0)) #Print the compass to the frame. cv2.putText(frame,"Bot: "+headingDeg+" Deg",(20,100),cv2.FONT_HERSHEY_COMPLEX_SMALL,.7,(0,0,0)) cv2.putText(frame,"Target: "+strTargetDegs+" Deg",(20,120),cv2.FONT_HERSHEY_COMPLEX_SMALL,.7,(0,0,0)) #Dots eaten. cv2.putText(frame,"Dots Ate: "+str(dots),(20,140),cv2.FONT_HERSHEY_COMPLEX_SMALL,.7,(0,0,0)) #After the frame has been modified to hell, show it. cv2.imshow('frame',frame) #Color image cv2.imshow('thresh',thresh2) #Black-n-White Threshold image#/// End CV Draw ////////////////////////////////////// | 276 277 278 279 280 281 282 283 |
181: Quand nous trouver l’angle entre le robot et la cible, puis le convertir en degrés, il finit par nous donner un numéro qui est un flotteur. C’est plus que nous avons besoin, donc, ici nous convertir le flotteur ()degs) à et entier (targetDegs) afin que nous pouvons comparer à la boussole du robot.
184: Nous déclarons une chaîne vide, appelée strTargetDegs.
187: Puis nous convertir le flotteur degs en une chaîne, donc nous pouvons imprimer l’angle de la cible sur l’écran à la ligne 264.