def read_camera(path, camera, cnt): #print("Tryna Read") img = camera.read() jpg = bgr8_to_jpeg(img) f = open(path.replace("*", str(cnt)), "wb") f.write(jpg) f.close()
def execute(change): image = change['new'] data = preprocess(image) cmap, paf = model_trt(data) cmap, paf = cmap.detach().cpu(), paf.detach().cpu() counts, objects, peaks = parse_objects( cmap, paf) #, cmap_threshold=0.15, link_threshold=0.15) draw_objects(image, counts, objects, peaks) image_w.value = bgr8_to_jpeg(image[:, ::-1, :])
def __execute(self, change): image = change['new'] data = self.__preprocess(image) cmap, paf = self.model_trt(data) cmap, paf = cmap.detach().cpu(), paf.detach().cpu() counts, objects, peaks = self.parse_objects(cmap, paf) keypoints = self.keypoint_coordinates(image, counts, objects, peaks) self.image_pub.publish(self.bridge.cv2_to_imgmsg(image, "bgr8")) if self.display_widget: self.display_widget.value = bgr8_to_jpeg(image[:, ::-1, :]) else: self.display.set_data(image[:, :, ::-1]) plt.pause(0.000001) return keypoints
def save_snapshot(_, content, msg): if content['event'] == 'click': data = content['eventData'] x = data['offsetX'] y = data['offsetY'] # save to disk dataset.save_entry(category_widget.value, camera.value, x, y) # display saved snapshot snapshot = camera.value.copy() snapshot = cv2.circle(snapshot, (x, y), 8, (0, 255, 0), 3) snapshot_widget.value = bgr8_to_jpeg(snapshot) count_widget.value = dataset.get_count(category_widget.value)
def live(state_widget, model, camera, prediction_widget): global dataset while state_widget.value == 'live': image = camera.value preprocessed = preprocess(image) output = model(preprocessed).detach().cpu().numpy().flatten() category_index = dataset.categories.index(category_widget.value) x = output[2 * category_index] y = output[2 * category_index + 1] x = int(camera.width * (x / 2.0 + 0.5)) y = int(camera.height * (y / 2.0 + 0.5)) prediction = image.copy() prediction = cv2.circle(prediction, (x, y), 8, (255, 0, 0), 3) prediction_widget.value = bgr8_to_jpeg(prediction)
def execute(change): global frame_num frame_num = frame_num + 1 image = change['new'] data = preprocess(image) cmap, paf = model_trt(data) cmap, paf = cmap.detach().cpu(), paf.detach().cpu() counts, objects, peaks = parse_objects(cmap, paf)#, cmap_threshold=0.15, link_threshold=0.15) draw_objects(image, counts, objects, peaks) # image = cv2.rotate(image, cv2.cv2.ROTATE_90_COUNTERCLOCKWISE) image_w.value = bgr8_to_jpeg(image[:, ::-1, :]) clear_output(wait=True) keypoints = [] for keypoint in peaks[0]: keypoints.append(keypoint[0]) print_to_file(keypoints) print(f"{keypoints}", end='\r')
""" Simple test script to validate the motor controls and the steering and the camera and the ultrasonic sensors """ from jetcam.csi_camera import CSICamera import ipywidgets from IPython.display import display from jetcam.utils import bgr8_to_jpeg camera_in = CSICamera(width=224, height=224, capture_width=1080, capture_height=720, capture_fps=30) # Default Nvidia Camera Setup image_widget = ipywidgets.Image(format='jpeg') while True: image_widget.value = bgr8_to_jpeg(camera_in.read()) display(image_widget) # Test motors import actuators drive_train = actuators.ServoMotor()
def read_camera(path, camera, cnt): img = camera.read() jpg = bgr8_to_jpeg(img) f = open(path + "car_frame_" + str(cnt) + ".jpg", "wb") f.write(jpg) f.close()
from jetcam.csi_camera import CSICamera camera = CSICamera(width=224, height=224) image = camera.read() print(image.shape) print(camera.value.shape) import ipywidgets from IPython.display import display from jetcam.utils import bgr8_to_jpeg image_widget = ipywidgets.Image(format='jpeg') image_widget.value = bgr8_to_jpeg(image) display(image_widget)
def read_camera(camera, cnt): img = camera.read() jpg = bgr8_to_jpeg(img) f = open("images/cap" + str(cnt) + ".jpg", "wb") f.write(jpg) f.close()
import os import traitlets #import ipywidgets.widgets as widgets #from IPython.display import display #from jetbot import Camera, bgr8_to_jpeg from uuid import uuid1 from jetcam.usb_camera import USBCamera from jetcam.utils import bgr8_to_jpeg directory = '.' # Start the camera and create a video stream #camera = USBCamera(capture_device=1) camera = USBCamera(width=224, height=224, capture_width=640, capture_height=480, capture_device=0) print(camera.value.shape) # Get an bgr8 image from the camera image = camera.read() print(camera.value.shape) toJpeg = bgr8_to_jpeg(image) image_path = os.path.join(directory, str(uuid1()) + '.jpg') with open(image_path, 'wb') as f: f.write(image.value)
def update_image(change): image = change['new'] image_widget.value = bgr8_to_jpeg(image)