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
99
Set target color, HSV color space
'''
colorUpper = np.array([44, 255, 255])
colorLower = np.array([24, 100, 100])
font = cv2.FONT_HERSHEY_SIMPLEX
class Camera(BaseCamera):
video_source = 0
def __init__(self):
if os.environ.get('OPENCV_CAMERA_SOURCE'):
Camera.set_video_source(int(os.environ['OPENCV_CAMERA_SOURCE']))
super(Camera, self).__init__()
@staticmethod
def set_video_source(source):
Camera.video_source = source
@staticmethod
def frames():
camera = cv2.VideoCapture(Camera.video_source)
if not camera.isOpened():
raise RuntimeError('Could not start camera.')
while True:
# read current frame
img = camera.read() #Get the picture captured by the camera
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) #Convert captured images to HSV color space
mask = cv2.inRange(hsv, colorLower, colorUpper) #Traverse the colors in the target color range in the HSV
color space, and turn these color blocks into masks
mask = cv2.erode(mask, None, iterations=2) #Corrosion of small pieces of mask (noise) in the picture
becomes small (small pieces of color or noise disappear)
mask = cv2.dilate(mask, None, iterations=2) #Inflate, and resize the large mask that was reduced in the
previous step to its original size
cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)[-2] #Find a few masks in the picture
center = None
if len(cnts) > 0: #If the number of whole masks in the picture is greater than one
'''
Find the coordinates of the center point of the object of the target color and the size of the object in
the picture