def __init__(self): pyrs.start() self.dev = pyrs.Device() self.dev.apply_ivcam_preset(0) self.dev.set_device_option(rs_option.RS_OPTION_F200_LASER_POWER, 15.0) self.worker = FrameWorker(self) self.worker.start()
def video_feed(): return Response(gen( pyrs.Device( device_id=0, streams=[pyrs.ColourStream(fps=30), pyrs.DepthStream(fps=30)])), mimetype='multipart/x-mixed-replace; boundary=frame')
def test_is_wrapped(self): cam = pyrs.Device() cam.wait_for_frames() from pyrealsense import rsutilwrapper pc = cam.points dm = cam.depth nz = np.nonzero(pc) x0, y0 = nz[0][0], nz[1][0] pixel0 = np.ones(2, dtype=np.float32) * np.NaN point0 = pc[x0, y0].astype(np.float32) rsutilwrapper.project_point_to_pixel(pixel0, cam.depth_intrinsics, point0) point1 = np.zeros(3, dtype=np.float32) x1, y1 = np.round(pixel0[1]).astype(int), np.round( pixel0[0]).astype(int) self.assertTrue(np.isclose([x0, y0], [x1, y1], atol=2).all()) depth = dm[x0, y0] * cam.depth_scale rsutilwrapper.deproject_pixel_to_point(point1, cam.depth_intrinsics, pixel0, depth) self.assertTrue(np.isclose(point0, point1, atol=10e-3).all())
def __init__(self): # Using OpenCV to capture from device 0. If you have trouble capturing # from a webcam, comment the line below out and use a video file # instead. pyrs.start() caffe.set_mode_gpu() self.dev = pyrs.Device() self.dev.set_device_option( pyrs.constants.rs_option.RS_OPTION_COLOR_ENABLE_AUTO_EXPOSURE, 1) self.dev.set_device_option( pyrs.constants.rs_option.RS_OPTION_R200_LR_AUTO_EXPOSURE_ENABLED, 1) print 'start net init' self.net = caffe.Net( '/home/rafi/test_fcn/fcn.berkeleyvision.org-master/voc-fcn32s/deploy.prototxt', '/home/rafi/test_fcn/fcn.berkeleyvision.org-master/voc-fcn32s/fcn32s-heavy-pascal.caffemodel', caffe.TEST) print 'finished net init'
# video_capture = cv2.VideoCapture(0) # Load a sample picture and learn how to recognize it. obama_image = face_recognition.load_image_file("obama.jpg") obama_face_encoding = face_recognition.face_encodings(obama_image)[0] tyler_image = face_recognition.load_image_file("tyler.jpg") tyler_face_encoding = face_recognition.face_encodings(tyler_image)[0] # Initialize some variables face_locations = [] face_encodings = [] face_names = [] process_this_frame = True with pyrs.Service() as a, pyrs.Device() as dev: while True: dev.wait_for_frames() c = dev.color c = cv2.cvtColor(c, cv2.COLOR_RGB2BGR) #cv2.imshow('', c) if cv2.waitKey(1) & 0xFF == ord('q'): break # Grab a single frame of video frame = c # Resize frame of video to 1/4 size for faster face recognition processing small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
def rs_transform_point_to_point(to_point, extrin, from_point): to_point[0] = extrin.rotation[0] * from_point[0] + extrin.rotation[ 3] * from_point[1] + extrin.rotation[6] * from_point[ 2] + extrin.translation[0] to_point[1] = extrin.rotation[1] * from_point[0] + extrin.rotation[ 4] * from_point[1] + extrin.rotation[7] * from_point[ 2] + extrin.translation[1] to_point[2] = extrin.rotation[2] * from_point[0] + extrin.rotation[ 5] * from_point[1] + extrin.rotation[8] * from_point[ 2] + extrin.translation[2] with pyrs.Service(): dev = pyrs.Device() extrinsics = dev.get_device_extrinsics(dev.streams[1].stream, dev.streams[0].stream) dev.wait_for_frames() while True: c = dev.color temp = dev.depth cad = dev.cad plt.imshow(temp) plt.show() print("creating aligned depth image of shape", temp.shape) depth_point = np.zeros(3, dtype=np.float32)
# resize for faster processing resize_factor = 0.5 # store whether a face was detected nearby face_nearby = False # store how many following frames no Face was detected nearby # used to be more resistant for single frames with missing face detection. no_face_detect_counter = 0 # init realsense device dev = pyrs.Device(device_id=0, streams=[ pyrs.ColourStream(width=x_pixel, height=y_pixel, fps=30), pyrs.DepthStream() ]) # Init MTCNN for Face Detection sess = tf.Session(config=tf.ConfigProto(log_device_placement=False)) pnet, rnet, onet = detect_face.create_mtcnn(sess, None) minsize = 20 # minimum size of face threshold = [0.6, 0.7, 0.7] # three steps's threshold factor = 0.709 # scale factor # Init Facenet for face recognition print('Initializing Facenet...') tree_model = "models/Tree/own.mod" svm_model = "models/SVM/svm_lfw.mod"
btn_name = button_names.get(btn, 'unknown(0x%03x)' % btn) button_map.append(btn_name) button_states[btn_name] = 0 print('{:d} axes found '.format(num_axes)) print('{:d} buttons found '.format(num_buttons)) # Go into driving motors with a loop motorrunning = True # Start RealSense camera pyrs.start() py_dev = pyrs.Device( device_id=0, streams=[pyrs.ColourStream(fps=30), pyrs.DepthStream(fps=30)]) # begin loop while motorrunning: evbuf = jsdev.read(8) if evbuf: time, value, type, number = struct.unpack('IhBB', evbuf) if type & 0x80: print("(initial)") if type & 0x01: print(value)
def init_device(): pyrs.start() dev = pyrs.Device() return dev
def test_is_not_created(self): try: pyrs.Device() except RealsenseError as e: self.assertTrue(e.function == 'rs_get_device')
from PIL import Image import numpy as np ## setup logging import logging logging.basicConfig(level=logging.INFO) ## import the package import pyrealsense as pyrs ## start the service - also available as context manager pyrs.start() ## create a device from device id and streams of interest cam = pyrs.Device(device_id=0, streams=[pyrs.stream.ColorStream(fps=60)]) ## retrieve 60 frames of data for _ in range(20): cam.wait_for_frames() print(cam.color) a = cam.color print("stopped") ## stop camera and service cam.stop() pyrs.stop() plt.imshow(a, cmap='hot', interpolation='nearest') a = Image.fromarray(a) a.save('mph1.png')
def test_is_not_created(self): cam = pyrs.Device() cam.wait_for_frames() self.assertTrue(cam.color.any()) cam.stop()
def start(self): pyrs.start() self.device = pyrs.Device(device_id=0)
from .network import network_table, run as run_network from .constants import IR_RESOLUTION # process argv DEBUG = 'debug' in sys.argv MOCK = 'mock' in sys.argv if 'boiler' in sys.argv: FORCE = 'BOILER' elif 'peg' in sys.argv: FORCE = 'PEG' else: FORCE = None if not MOCK: import pyrealsense as pyrs from pyrealsense.stream import ColourStream, DepthStream from .streams import InfraredStream pyrs.start() rs = pyrs.Device(streams = [ColourStream(), DepthStream(), InfraredStream()]) clock.init('roborio-2471-frc.local', 8082) processor = None net_in_q = Queue() net_out_q = Queue() network_thread = Thread(target = run_network, args=(net_in_q, net_out_q)) network_thread.daemon = True network_thread.start() network_table.putString('Mode', 'IDLE')