Tutorial
Table Of Contents
- 1. Premise
- 2. Raspberry Pi System Installation and Developmen
- 3 Log In to The Raspberry Pi and Install The App
- 4 Assembly and Precautions
- 5 Controlling Robot via WEB App
- 6 Common Problems and Solutions(Q&A)
- 7 Set The Program to Start Automatically
- 8 Remote Operation of Raspberry Pi Via MobaXterm
- 9 How to Control WS2812 RGB LED
- 10 How to Control The Servo
- 11 How to Control DC Motor
- 12 Ultrasonic Module
- 13 Line Tracking
- 14 Make A Police Light or Breathing Light
- 15 Real-Time Video Transmission
- 16 Automatic Obstacle Avoidance
- 17 Why OpenCV Uses Multi-threading to Process Vide
- 18 OpenCV Learn to Use OpenCV
- 19 Using OpenCV to Realize Color Recognition and T
- 20 Machine Line Tracking Based on OpenCV
- 21 Create A WiFi Hotspot on The Raspberry Pi
- 22 Install GUI Dependent Item under Window
- 23 How to Use GUI
- 24 Control The WS2812 LED via GUI
- 25 Real-time Video Transmission Based on OpenCV
- 26 Use OpenCV to Process Video Frames on The PC
- 27 Enable UART
- 28 Control Your AWR with An Android Device
- Conclusion
104
Convert the picture to black and white, and then binarize (the value of each pixel in the picture is 255
except 0)
'''
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
retval, img = cv2.threshold(img, 0, 255, cv2.THRESH_OTSU)
img = cv2.erode(img, None, iterations=6) #Use Corrosion Denoising
colorPos = img[linePos] #Get an array of pixel values for linePos
try:
lineColorCount_Pos = np.sum(colorPos == lineColorSet) #Get the number of pixels of line color
(line width)
lineIndex_Pos = np.where(colorPos == lineColorSet) #Get the horizontal position of the end
point of the line in the linePos line
'''
Use the endpoint position and line width to calculate the position of the center point of the line
'''
left_Pos = lineIndex_Pos[0][lineColorCount_Pos-1]
right_Pos = lineIndex_Pos[0][0]
center_Pos = int((left_Pos+right_Pos)/2)
print('The position of the center point of the line is:%d'%center_Pos)
except:
'''
If no line is detected, the line width above 0 will cause an error, so that you know that no line has
been detected
'''
center_Pos = 0
print('No line detected')
'''
Draw a horizontal reference line
'''
cv2.line(img,(0,linePos),(640,linePos),(255,255,64),1)
if center_Pos:
'''
If a line is detected, draw the center point of the line
'''
cv2.line(img,(center_Pos,linePos+300),(center_Pos,linePos-300),(255,255,64),1)
# encode as a jpeg image and return it
yield cv2.imencode('.jpg', img)[1].tobytes()