def main(self): web = Webserver(balloon_config.config.parser, (lambda: self.frame)) # initialise camera balloon_video.init_camera() video_writer = balloon_video.open_video_writer() # get start time start_time = time.time() # loop for 10 seconds looking for circles while (time.time() - start_time < 20): # Take each frame frame = balloon_video.capture_image() self.frame = frame # is there the x & y position in frame of the largest balloon found_in_image, xpos, ypos, size = self.analyse_frame(frame) # display image cv2.imshow('frame', frame) # write the frame video_writer.write(frame) # exit if user presses ESC k = cv2.waitKey(5) & 0xFF if k == 27: break print "exiting..." web.close() # uncomment line below if window with real-time video was displayed cv2.destroyAllWindows() # release camera balloon_video.close_camera()
def main(self): web = Webserver(balloon_config.config.parser, (lambda : self.frame)) # initialise camera balloon_video.init_camera() video_writer = balloon_video.open_video_writer() # get start time start_time = time.time() # loop for 10 seconds looking for circles while(time.time() - start_time < 20): # Take each frame frame = balloon_video.capture_image() self.frame = frame # is there the x & y position in frame of the largest balloon found_in_image, xpos, ypos, size = self.analyse_frame(frame) # display image cv2.imshow('frame',frame) # write the frame video_writer.write(frame) # exit if user presses ESC k = cv2.waitKey(5) & 0xFF if k == 27: break print "exiting..." web.close() # uncomment line below if window with real-time video was displayed cv2.destroyAllWindows() # release camera balloon_video.close_camera()
def run(self): # initialise video capture balloon_video.init_camera() # create trackbars for color change cv2.namedWindow('Colour Filters') cv2.createTrackbar('Hue min', 'Colour Filters', self.h_low, 255, self.empty_callback) cv2.createTrackbar('Hue max', 'Colour Filters', self.h_high, 255, self.empty_callback) cv2.createTrackbar('Sat min', 'Colour Filters', self.s_low, 255, self.empty_callback) cv2.createTrackbar('Sat max', 'Colour Filters', self.s_high, 255, self.empty_callback) cv2.createTrackbar('Bgt min', 'Colour Filters', self.v_low, 255, self.empty_callback) cv2.createTrackbar('Bgt max', 'Colour Filters', self.v_high, 255, self.empty_callback) cv2.createTrackbar('Save', 'Colour Filters', 0, 10, self.save_callback) while (True): # get a frame frame = balloon_video.capture_image() output = frame.copy() # Convert BGR to HSV hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # get latest trackbar positions self.h_low = cv2.getTrackbarPos('Hue min', 'Colour Filters') self.h_high = cv2.getTrackbarPos('Hue max', 'Colour Filters') self.s_low = cv2.getTrackbarPos('Sat min', 'Colour Filters') self.s_high = cv2.getTrackbarPos('Sat max', 'Colour Filters') self.v_low = cv2.getTrackbarPos('Bgt min', 'Colour Filters') self.v_high = cv2.getTrackbarPos('Bgt max', 'Colour Filters') # use trackbar positions to filter image colour_low = np.array([self.h_low, self.s_low, self.v_low]) colour_high = np.array([self.h_high, self.s_high, self.v_high]) # Threshold the HSV image mask = cv2.inRange(hsv_frame, colour_low, colour_high) #PAPOU_MOD Hough Circle #gray = cv2.cvtColor(mask, cv2.COLOR_HSV2GRAY) blurred = cv2.GaussianBlur(mask, (3, 3), 0) #circles = cv2.HoughCircles(blurred, cv2.cv.CV_HOUGH_GRADIENT, 1.9, 60) # ensure at least some circles were found #if circles is not None: # convert the (x, y) coordinates and radius of the circles to integers #circles = np.round(circles[0, :]).astype("int") # loop over the (x, y) coordinates and radius of the circles #for (x, y, r) in circles: # draw the circle in the output image, then draw a rectangle # corresponding to the center of the circle #cv2.circle(output, (x, y), r, (0, 255, 0), 4) #cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1) # Erode erode_kernel = np.ones((3, 3), np.uint8) eroded_img = cv2.erode(blurred, erode_kernel, iterations=2) # dilate dilate_kernel = np.ones((7, 7), np.uint8) dilated_img = cv2.dilate(eroded_img, dilate_kernel, iterations=1) # Bitwise-AND mask and original image res = cv2.bitwise_and(frame, frame, mask=dilated_img) #cv2.imshow('Original',frame) cv2.imshow('Mask', mask) cv2.imshow('Gaussian Blur', blurred) cv2.imshow('Filtered Result', res) #cv2.imshow('resultat', np.hstack([frame, output])) #cv2.imshow('resultat', output) k = cv2.waitKey(5) & 0xFF if k == 27: break # close camera frame = balloon_video.close_camera() # close all windows cv2.destroyAllWindows()
def run(self): # initialise video capture balloon_video.init_camera() # create trackbars for color change cv2.namedWindow('Colour Filters') cv2.createTrackbar('Hue min', 'Colour Filters', self.h_low, 255, self.empty_callback) cv2.createTrackbar('Hue max', 'Colour Filters', self.h_high, 255, self.empty_callback) cv2.createTrackbar('Sat min', 'Colour Filters', self.s_low, 255, self.empty_callback) cv2.createTrackbar('Sat max', 'Colour Filters', self.s_high, 255, self.empty_callback) cv2.createTrackbar('Bgt min', 'Colour Filters', self.v_low, 255, self.empty_callback) cv2.createTrackbar('Bgt max', 'Colour Filters', self.v_high, 255, self.empty_callback) cv2.createTrackbar('Save', 'Colour Filters', 0, 10, self.save_callback) while (True): # get a frame frame = balloon_video.capture_image() # Convert BGR to HSV hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # get latest trackbar positions self.h_low = cv2.getTrackbarPos('Hue min', 'Colour Filters') self.h_high = cv2.getTrackbarPos('Hue max', 'Colour Filters') self.s_low = cv2.getTrackbarPos('Sat min', 'Colour Filters') self.s_high = cv2.getTrackbarPos('Sat max', 'Colour Filters') self.v_low = cv2.getTrackbarPos('Bgt min', 'Colour Filters') self.v_high = cv2.getTrackbarPos('Bgt max', 'Colour Filters') # use trackbar positions to filter image colour_low = np.array([self.h_low, self.s_low, self.v_low]) colour_high = np.array([self.h_high, self.s_high, self.v_high]) # Threshold the HSV image mask = cv2.inRange(hsv_frame, colour_low, colour_high) #PAPOU_MOD Blur & Erode blurred = cv2.GaussianBlur(mask, (3, 3), 0) # Erode erode_kernel = np.ones((3, 3), np.uint8) #eroded_img = cv2.erode(mask,erode_kernel,iterations = 1) eroded_img = cv2.erode(blurred, erode_kernel, iterations=2) # dilate #dilate_kernel = np.ones((10,10),np.uint8); dilate_kernel = np.ones((7, 7), np.uint8) dilated_img = cv2.dilate(eroded_img, dilate_kernel, iterations=1) # Bitwise-AND mask and original image res = cv2.bitwise_and(frame, frame, mask=dilated_img) cv2.imshow('Original', frame) cv2.imshow('Mask', mask) cv2.imshow('Filtered Result', res) #cv2.imshow('grey_res',grey_res) k = cv2.waitKey(5) & 0xFF if k == 27: break # close camera frame = balloon_video.close_camera() # close all windows cv2.destroyAllWindows()
def run(self): # initialise video capture balloon_video.init_camera() # create trackbars for color change cv2.namedWindow('Colour Filters') cv2.createTrackbar('Hue min','Colour Filters',self.h_low,255,self.empty_callback) cv2.createTrackbar('Hue max','Colour Filters',self.h_high,255,self.empty_callback) cv2.createTrackbar('Sat min','Colour Filters',self.s_low,255,self.empty_callback) cv2.createTrackbar('Sat max','Colour Filters',self.s_high,255,self.empty_callback) cv2.createTrackbar('Bgt min','Colour Filters',self.v_low,255,self.empty_callback) cv2.createTrackbar('Bgt max','Colour Filters',self.v_high,255,self.empty_callback) cv2.createTrackbar('Save','Colour Filters',0,10,self.save_callback) while(True): # get a frame frame = balloon_video.capture_image() # Convert BGR to HSV hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # get latest trackbar positions self.h_low = cv2.getTrackbarPos('Hue min','Colour Filters') self.h_high = cv2.getTrackbarPos('Hue max','Colour Filters') self.s_low = cv2.getTrackbarPos('Sat min','Colour Filters') self.s_high = cv2.getTrackbarPos('Sat max','Colour Filters') self.v_low = cv2.getTrackbarPos('Bgt min','Colour Filters') self.v_high = cv2.getTrackbarPos('Bgt max','Colour Filters') # use trackbar positions to filter image colour_low = np.array([self.h_low,self.s_low,self.v_low]) colour_high = np.array([self.h_high,self.s_high,self.v_high]) # Threshold the HSV image mask = cv2.inRange(hsv_frame, colour_low, colour_high) # Erode erode_kernel = np.ones((3,3),np.uint8); eroded_img = cv2.erode(mask,erode_kernel,iterations = 1) # dilate dilate_kernel = np.ones((10,10),np.uint8); dilated_img = cv2.dilate(eroded_img,dilate_kernel,iterations = 1) # Bitwise-AND mask and original image res = cv2.bitwise_and(frame,frame, mask=dilated_img) cv2.imshow('Original',frame) cv2.imshow('Mask',mask) cv2.imshow('Filtered Result',res) #cv2.imshow('grey_res',grey_res) k = cv2.waitKey(5) & 0xFF if k == 27: break # close camera frame = balloon_video.close_camera() # close all windows cv2.destroyAllWindows()