Every line of 'opencv capture image from camera python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
25 def camera_callback(camera): 26 '''Convert sensor_msg::Image to an image''' 27 global lock, image, steering, throttle, cv_bridge 28 if lock.acquire(True): 29 image = cv_bridge.imgmsg_to_cv2(camera) 30 lock.release()
268 def captureImage(self): 269 check(uc480.is_FreezeVideo(self, IS_WAIT), "is_FreezeVideo") 270 return self.getImage()
116 def get_image_bgr(self): 117 with self.output_bgr.condition: 118 self.output_bgr.condition.wait() 119 return self.output_bgr.frame
423 def takeImage(self): 424 self.isCapturingImage = True 425 self.imageCapture.capture()
46 def _camera_callback(self, image): 47 48 frame = self._cv_br.imgmsg_to_cv2(image) 49 50 self._roi_lock.acquire() 51 for roi in self._latest_rois: 52 cv2.rectangle(frame, (roi.x, roi.y), 53 (roi.x + roi.w, roi.y + roi.h), (0, 255, 0), 10) 54 self._roi_lock.release() 55 56 maxClass = None 57 maxConf = 0.0 58 self._class_lock.acquire() 59 for c in self._latest_classes: 60 if c.confidence > maxConf: 61 maxConf = c.confidence 62 maxClass = c 63 self._class_lock.release() 64 65 if maxClass is not None: 66 cv2.putText(frame, "%.1f%% : %s" % (maxConf*100, maxClass.desc), (60, 60), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 3, cv2.LINE_AA) 67 68 self._publisher.publish(self._cv_br.cv2_to_imgmsg(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)))
145 def capture_image_pygame(self, camera_path: str, image_path: str) -> None: 146 """Captures an image with pygame.""" 147 self.logger.debug("Capturing image from camera: {}".format(camera_path)) 148 149 # Capture image 150 try: 151 152 # Check if simulated 153 # if self.simulate: 154 # message = "Simulating capture, saving image to: {}".format(image_path) 155 # self.logger.info(message) 156 # command = "cp {} {}".format(self.SIMULATION_IMAGE_PATH, image_path) 157 # os.system(command) 158 # return 159 160 # Capture and save image 161 if not self._simulate_capture(image_path): 162 resolution_array = self.resolution.split("x") 163 resolution = (int(resolution_array[0]), int(resolution_array[1])) 164 camera = pygame.camera.Camera(camera_path, resolution) 165 camera.start() 166 image = camera.get_image() 167 pygame.image.save(image, image_path) 168 camera.stop() 169 170 except Exception as e: 171 raise exceptions.CaptureImageError(logger=self.logger) from e
46 def init_camera(self): 47 # create the device 48 self._device = hg.cvCreateCameraCapture(self._index) 49 50 # Set preferred resolution 51 cv.SetCaptureProperty(self._device, cv.CV_CAP_PROP_FRAME_WIDTH, 52 self.resolution[0]) 53 cv.SetCaptureProperty(self._device, cv.CV_CAP_PROP_FRAME_HEIGHT, 54 self.resolution[1]) 55 56 # and get frame to check if it's ok 57 frame = hg.cvQueryFrame(self._device) 58 # Just set the resolution to the frame we just got, but don't use 59 # self.resolution for that as that would cause an infinite recursion 60 # with self.init_camera (but slowly as we'd have to always get a frame). 61 self._resolution = (int(frame.width), int(frame.height)) 62 63 #get fps 64 self.fps = cv.GetCaptureProperty(self._device, cv.CV_CAP_PROP_FPS) 65 if self.fps <= 0: 66 self.fps = 1 / 30. 67 68 if not self.stopped: 69 self.start()
4 def main(): 5 capture = cv2.VideoCapture(0) 6 eye_path = "../classifier/haarcascade_eye.xml" 7 face_path = "../classifier/haarcascade_frontalface_default.xml" 8 9 eye_cascade = cv2.CascadeClassifier(eye_path) 10 face_cascade = cv2.CascadeClassifier(face_path) 11 12 while (True): 13 _, frame = capture.read() 14 15 gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 16 17 eyes = eye_cascade.detectMultiScale(gray_frame, scaleFactor=1.05, minNeighbors=5, minSize=(10,10)) 18 faces = face_cascade.detectMultiScale(gray_frame, scaleFactor=1.05, minNeighbors=5, minSize=(40, 40)) 19 20 print("Number of eyes : " + str(len(eyes))) 21 print("Number of faces : " + str(len(faces))) 22 23 for (x, y, w, h) in eyes: 24 cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2) 25 26 for (x, y, w, h) in faces: 27 cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) 28 29 cv2.imshow("Live Capture", frame) 30 31 if cv2.waitKey(1) == 27: 32 break 33 34 cv2.destroyAllWindows() 35 capture.release()
40 def take_normal_exposure_still(self, pic_path, image_width, image_height): 41 with picamera.PiCamera() as camera: 42 camera.resolution = (image_width, image_height) 43 camera.capture(pic_path)
185 def display(self, data): 186 cv2.imshow('frame', self.image.Convert(self.display_format, PySpin.HQ_LINEAR).GetNDArray()) 187 # waitKey helps primitive UI cycle through events 188 cv2.waitKey(1)