Image recognition
Now, to go ahead and start doing vision processing, let's connect the camera to Raspberry Pi. Once you have done that, you need to write the following code:
import cv2 import numpy as np cap = cv2.VideoCapture(0) while True: _, image = cap.read() cv2.imshow("Frame", image) hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) lowerGreen = np.array([80,50,50]) upperGreen = np.array([130,255,255]) mask = cv2.inRange(hsv, lowerGreen, upperGreen) res = cv2.bitwise_and(image, image, mask=mask) cv2.imshow('mask',mask) cv2.imshow('result',res) key = cv2.waitKey(1) & 0xFF if key == ord('q'): break cv2.destroyAllWindows() cap.release()
Before you actually compile this code, let me tell you what exactly we are doing:
import numpy as np
In the preceding line, we are importing the library numpy
as np
, or in other words, we have imported the library, and every time we need to call is...