1.Color Detection:
Color is one of the most important features of an image .Many of the challenges
in the field of robotics can be solved using simple color based techniques instead of using complex algorithms
import cv2 import numpy as np cap=cv2.VideoCapture(0) while(1): ret,frame=cap.read() im=cv2.bilateralFilter(frame,10,100,100) #fading image leaving edges im1=cv2.cvtColor(im,cv2.COLOR_BGR2HSV) #converting into HSV low_or=np.array([6,100,150]) high_or=np.array([18,255,255]) # range of HSV values to detect im2=cv2.inRange(im1,low_or,high_or) # kernal=np.ones((7,7),np.uint8) erode=cv2.erode(im2,kernal) # opening(erosion then dilate) dilate1=cv2.dilate(erode,kernal) cv2.imshow('r1',frame) cv2.imshow('r',dilate1) k=cv2.waitKey(20) if k==27:# waiting for ESC key break cap.release()#release capturing(important) cv2.destroyAllWindows() #close windows
2.Circle detection:
Circle detection can be quite useful in many fields like biology to detect cells,bacteria,etc., from the images captured by the microscope,robotics to make tennis playing robots etc.
import cv2 import numpy as np cap=cv2.VideoCapture(0) while(1): ret,frame=cap.read() im=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) circles = cv2.HoughCircles(im,cv2.cv.CV_HOUGH_GRADIENT,1,20,np.array([]),param1=50,param2=30,minRadius=125,ma xRadius=150) if circles is None: cv2.imshow('sivA',frame) else: for i in circles[0,:]: # draw the outer circle cv2.circle(im,(i[0],i[1]),i[2],(0,255,0),2) # draw the center of the circle cv2.circle(im,(i[0],i[1]),2,(0,0,255),3) cv2.imshow("sivA",im) k=cv2.waitKey(50) if k==27: break cv2.destroyAllWindows() # SYNTAX : cv2.HoughCircles(image, method, dp, minDist) #image: 8-bit, single channel image. If working with a color image, convert to grayscale first. #method: Defines the method to detect circles in images. Currently, the only implemented method is cv2.HOUGH_GRADIENT, which corresponds to the Yuen et al. paper. #dp: This parameter is the inverse ratio of the accumulator resolution to the image resolution (see Yuen et details). Essentially, the larger the dp gets, the smaller the accumulator array gets. #minDist: Minimum distance between the center (x, y) coordinates of detected circles. If the minDist is too small, multiple circles in the same neighborhood as the original may be (falsely) detected