Python cv.WaitKey() Examples
The following are 6
code examples of cv.WaitKey().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv
, or try the search function
.
Example #1
Source File: demo_cv_thresh_sweep.py From SimpleCV2 with BSD 3-Clause "New" or "Revised" License | 5 votes |
def disp_thresh(lower, upper): depth, timestamp = freenect.sync_get_depth() depth = 255 * np.logical_and(depth > lower, depth < upper) depth = depth.astype(np.uint8) image = cv.CreateImageHeader((depth.shape[1], depth.shape[0]), cv.IPL_DEPTH_8U, 1) cv.SetData(image, depth.tostring(), depth.dtype.itemsize * depth.shape[1]) cv.ShowImage('Depth', image) cv.WaitKey(10)
Example #2
Source File: demo_cv_async.py From SimpleCV2 with BSD 3-Clause "New" or "Revised" License | 5 votes |
def display_depth(dev, data, timestamp): global keep_running cv.ShowImage('Depth', frame_convert.pretty_depth_cv(data)) if cv.WaitKey(10) == 27: keep_running = False
Example #3
Source File: demo_cv_async.py From SimpleCV2 with BSD 3-Clause "New" or "Revised" License | 5 votes |
def display_rgb(dev, data, timestamp): global keep_running cv.ShowImage('RGB', frame_convert.video_cv(data)) if cv.WaitKey(10) == 27: keep_running = False
Example #4
Source File: color-1.py From rpi-opencv with GNU General Public License v3.0 | 4 votes |
def run(self): while True: img = cv.QueryFrame( self.capture ) t1 = time.time() #blur the source image to reduce color noise cv.Smooth(img, img, cv.CV_BLUR, 3); #convert the image to hsv(Hue, Saturation, Value) so its #easier to determine the color to track(hue) hsv_img = cv.CreateImage(cv.GetSize(img), 8, 3) cv.CvtColor(img, hsv_img, cv.CV_BGR2HSV) #limit all pixels that don't match our criteria, in this case we are #looking for purple but if you want you can adjust the first value in #both turples which is the hue range(120,140). OpenCV uses 0-180 as #a hue range for the HSV color model thresholded_img = cv.CreateImage(cv.GetSize(hsv_img), 8, 1) # White sensitivity = 10 cv.InRangeS(hsv_img, (0, 0, 255-sensitivity), (255, sensitivity, 255), thresholded_img) # Red #cv.InRangeS(hsv_img, (0, 150, 0), (5, 255, 255), thresholded_img) # Blue #cv.InRangeS(hsv_img, (100, 50, 50), (140, 255, 255), thresholded_img) # Green #cv.InRangeS(hsv_img, (40, 50, 50), (80, 255, 255), thresholded_img) #determine the objects moments and check that the area is large #enough to be our object mat=cv.GetMat(thresholded_img) moments = cv.Moments(mat, 0) area = cv.GetCentralMoment(moments, 0, 0) #there can be noise in the video so ignore objects with small areas if(area > 10000): #determine the x and y coordinates of the center of the object #we are tracking by dividing the 1, 0 and 0, 1 moments by the area x = cv.GetSpatialMoment(moments, 1, 0)/area y = cv.GetSpatialMoment(moments, 0, 1)/area x = int(round(x)) y = int(round(y)) #create an overlay to mark the center of the tracked object overlay = cv.CreateImage(cv.GetSize(img), 8, 3) cv.Circle(overlay, (x, y), 2, (255, 255, 255), 20) cv.Add(img, overlay, img) #add the thresholded image back to the img so we can see what was #left after it was applied t2 = time.time() cv.Merge(thresholded_img, None, None, None, img) print "detection time = %gs x=%d,y=%d" % ( round(t2-t1,3) , x, y) #display the image cv.ShowImage(color_tracker_window, img) if cv.WaitKey(10) == 27: break
Example #5
Source File: ps3rover20.py From RoverPylot with GNU Lesser General Public License v3.0 | 4 votes |
def processVideo(self, jpegbytes, timestamp_10msec): # Update controller events pygame.event.pump() # Toggle lights self.lightsAreOn = self.checkButton(self.lightsAreOn, BUTTON_LIGHTS, self.turnLightsOn, self.turnLightsOff) # Toggle night vision (infrared camera) self.stealthIsOn = self.checkButton(self.stealthIsOn, BUTTON_STEALTH, self.turnStealthOn, self.turnStealthOff) # Move camera up/down if self.controller.get_button(BUTTON_CAMERA_UP): self.moveCameraVertical(1) elif self.controller.get_button(BUTTON_CAMERA_DOWN): self.moveCameraVertical(-1) else: self.moveCameraVertical(0) # Set treads based on axes self.setTreads(self.axis(1), self.axis(3)) # Display video image if possible try: if cv: # Save image to file on disk and load as OpenCV image fname = 'tmp.jpg' fd = open(fname, 'w') fd.write(jpegbytes) fd.close() image = cv.LoadImage(fname) # Show image cv.ShowImage(self.wname, image ) if cv.WaitKey(1) & 0xFF == 27: # ESC self.quit = True else: pass except: pass # Converts Y coordinate of specified axis to +/-1 or 0
Example #6
Source File: FPV_client.py From elijah-provisioning with Apache License 2.0 | 4 votes |
def FPV_thread(): global camera_index global capture global WINDOW_NAME global latest_frame global FPV_thread_stop global overlay_message # shared with application return results global face_position # shared with application return results FPV_init() cv.NamedWindow(WINDOW_NAME, cv.CV_WINDOW_NORMAL) cv.MoveWindow(WINDOW_NAME, 0, 0) width_scale = 1.0 height_scale = 1.0 while True: frame = cv.QueryFrame(capture) cv.Flip(frame, None, 1) #copy to buffer frame_lock.acquire() original_imagesize = (0,0) resized_imagesize = (0,0) if not latest_frame: latest_frame = cv.CreateImage((640, 480), frame.depth, frame.nChannels) original_imagesize = cv.GetSize(frame) resized_imagesize = cv.GetSize(latest_frame) width_scale = original_imagesize[0]*1.0/resized_imagesize[0] height_scale = original_imagesize[1]*1.0/resized_imagesize[1] cv.Resize(frame, latest_frame) frame_lock.release() #Display Result text_start_point = (10, 50) cv.PutText(frame, overlay_message, text_start_point, font, cv.Scalar(255,255,255)) cv.Rectangle(frame, text_start_point, (original_imagesize[0], 100), cv.Scalar(0,0,0), thickness=cv.CV_FILLED) if face_position[0] > 0.0: point1 = (int(face_position[0]*width_scale), int(face_position[1]*height_scale)) point2 = (int((face_position[0] + face_position[2])*width_scale), \ int((face_position[1]+face_position[3])*height_scale)) cv.Rectangle(frame, point1, point2, \ cv.Scalar(255, 255, 255), thickness=2) cv.ShowImage(WINDOW_NAME, frame) cv.ResizeWindow(WINDOW_NAME, 200, 100) cv.NamedWindow(WINDOW_NAME, cv.CV_WINDOW_NORMAL); cv.SetWindowProperty(WINDOW_NAME, 0, cv.CV_WINDOW_FULLSCREEN); c = cv.WaitKey(10) if c == ord('q'): break print "[INFO] FPV Thread is finished" FPV_thread_stop = True FPV_close()