Пример #1
0
 def getUsb2Mode(self):
     usb2_mode = False
     if self.args['force_usb2']:
         cli_print("FORCE USB2 MODE", PrintColors.WARNING)
         usb2_mode = True
     else:
         usb2_mode = False
     return usb2_mode
Пример #2
0
    def verifyBlobFilesExist(self, verifyBlob, verifyConfig):
        verifyBlobPath = Path(verifyBlob)
        verifyConfigPath = Path(verifyConfig)
        if not verifyBlobPath.exists():
            cli_print("\nWARNING: NN blob not found in: " + verifyBlob, PrintColors.WARNING)
            os._exit(1)

        if not verifyConfigPath.exists():
            print("NN config not found in: " + verifyConfig + '. Defaulting to "raw" output format!')
Пример #3
0
 def linuxCheckApplyUsbRules(self):
     if platform.system() == 'Linux':
         ret = subprocess.call(['grep', '-irn', 'ATTRS{idVendor}=="03e7"', '/etc/udev/rules.d'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
         if(ret != 0):
             cli_print("\nWARNING: Usb rules not found", PrintColors.WARNING)
             cli_print("\nSet rules: \n"
             """echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="03e7", MODE="0666"' | sudo tee /etc/udev/rules.d/80-movidius.rules \n"""
             "sudo udevadm control --reload-rules && udevadm trigger \n"
             "Disconnect/connect usb cable on host! \n", PrintColors.RED)
             os._exit(1)
Пример #4
0
def _stream_type(option):
    max_fps = None
    option_list = option.split(",")
    option_args = len(option_list)
    if option_args not in [1, 2]:
        msg_string = "{0} format is invalid. See --help".format(option)
        cli_print(msg_string, PrintColors.WARNING)
        raise ValueError(msg_string)

    transition_map = {"depth_raw" : "depth"}
    stream_name = option_list[0]
    if stream_name in transition_map:
        cli_print("Stream option " + stream_name + " is deprecated, use: " + transition_map[stream_name], PrintColors.WARNING)
        stream_name = transition_map[stream_name]

    if stream_name not in _stream_choices:
        msg_string = "{0} is not in available stream list: \n{1}".format(stream_name, _stream_choices)
        cli_print(msg_string, PrintColors.WARNING)
        raise ValueError(msg_string)

    if option_args == 1:
        stream_dict = {"name": stream_name}
    else:
        try:
            max_fps = float(option_list[1])
        except ValueError:
            msg_string = "In option: {0} {1} is not a number!".format(option, option_list[1])
            cli_print(msg_string, PrintColors.WARNING)

        stream_dict = {"name": stream_name, "max_fps": max_fps}
    return stream_dict
Пример #5
0
    def compileBlob(self, nn_model, model_compilation_target):
        blob_file, _ = self.getBlobFiles(nn_model)

        shave_nr = self.shave_nr
        cmx_slices = self.cmx_slices
        NCE_nr = self.NCE_nr

        if NCE_nr == 2:
            if shave_nr % 2 == 1 or cmx_slices % 2 == 1:
                raise ValueError("shave_nr and cmx_slices config must be even number when NCE is 2!")
            shave_nr_opt = int(shave_nr / 2)
            cmx_slices_opt = int(cmx_slices / 2)
        else:
            shave_nr_opt = int(shave_nr)
            cmx_slices_opt = int(cmx_slices)

        outblob_file = blob_file + ".sh" + str(shave_nr) + "cmx" + str(cmx_slices) + "NCE" + str(NCE_nr)
        if(not Path(outblob_file).exists()):
            cli_print("Compiling model for {0} shaves, {1} cmx_slices and {2} NN_engines ".format(str(shave_nr), str(cmx_slices), str(NCE_nr)), PrintColors.RED)
            ret = download_and_compile_NN_model(nn_model, model_zoo_folder, shave_nr_opt, cmx_slices_opt, NCE_nr, outblob_file, model_compilation_target)
            if(ret != 0):
                cli_print("Model compile failed. Falling back to default.", PrintColors.WARNING)
                raise RuntimeError("Model compilation failed! Not connected to the internet?")
            else:
                blob_file = outblob_file
        else:
            cli_print("Compiled mode found: compiled for {0} shaves, {1} cmx_slices and {2} NN_engines ".format(str(shave_nr), str(cmx_slices), str(NCE_nr)), PrintColors.GREEN)
            blob_file = outblob_file

        return blob_file
Пример #6
0
global args
try:
    args = vars(parse_args())
except:
    os._exit(2)

stream_list = args['streams']

if args['config_overwrite']:
    args['config_overwrite'] = json.loads(args['config_overwrite'])

print("Using Arguments=", args)

if args['force_usb2']:
    cli_print("FORCE USB2 MODE", PrintColors.WARNING)
    cmd_file = consts.resource_paths.device_usb2_cmd_fpath
else:
    cmd_file = consts.resource_paths.device_cmd_fpath

if args['dev_debug']:
    cmd_file = ''
    print('depthai will not load cmd file into device.')

calc_dist_to_bb = True
if args['disable_depth']:
    calc_dist_to_bb = False

decode_nn = decode_mobilenet_ssd
show_nn = show_mobilenet_ssd
Пример #7
0
try:
    args = vars(parse_args())
except:
    os._exit(2)

compile_model = args['shaves'] is not None and args['cmx_slices'] is not None and args['NN_engines']

stream_list = args['streams']

if args['config_overwrite']:
    args['config_overwrite'] = json.loads(args['config_overwrite'])

print("Using Arguments=",args)

if args['force_usb2']:
    cli_print("FORCE USB2 MODE", PrintColors.WARNING)
    cmd_file = consts.resource_paths.device_usb2_cmd_fpath
else:
    cmd_file = consts.resource_paths.device_cmd_fpath

if args['dev_debug']:
    cmd_file = ''
    print('depthai will not load cmd file into device.')

calc_dist_to_bb = True
if args['disable_depth']:
    calc_dist_to_bb = False

from depthai_helpers.mobilenet_ssd_handler import decode_mobilenet_ssd, show_mobilenet_ssd
decode_nn=decode_mobilenet_ssd
show_nn=show_mobilenet_ssd
Пример #8
0
 def test_cli_print_input_not_valid(self):
     with self.assertRaises(ValueError):
         cli_print("some message", "Not a valid type")
Пример #9
0
 def test_cli_print_valid(self):
     cli_print("some message", PrintColors.WARNING)
Пример #10
0
    def generateJsonConfig(self):

        # something to verify usb rules are good?
        self.linuxCheckApplyUsbRules()

        max_shave_nr = self.getMaxShaveNumbers()
        shave_nr = max_shave_nr if self.args['shaves'] is None else self.args['shaves']
        cmx_slices = shave_nr if self.args['cmx_slices'] is None else self.args['cmx_slices']
        NCE_nr = 1 if self.args['NN_engines'] is None else self.args['NN_engines']

        # left_right double NN check.
        if self.args['cnn_camera'] in ['left_right', 'rectified_left_right']:
            if NCE_nr != 2:
                cli_print('Running NN on both cams requires 2 NN engines!', PrintColors.RED)
                NCE_nr = 2

        if NCE_nr == 2:
            shave_nr = shave_nr - (shave_nr % 2)
            cmx_slices = cmx_slices - (cmx_slices % 2)

        # Get blob files
        blobMan = BlobManager(self.args, self.calc_dist_to_bb, shave_nr, cmx_slices, NCE_nr)
        self.NN_config = blobMan.getNNConfig()
        try:
            self.labels = self.NN_config['mappings']['labels']
        except:
            self.labels = None
            print("Labels not found in json!")

        try:
            output_format = self.NN_config['NN_config']['output_format']
        except:
            NN_json = {}
            NN_json['NN_config'] = {}
            NN_json['NN_config']['output_format'] = "raw"
            self.NN_config = NN_json
            output_format = "raw"

        if output_format == "raw" and self.calc_dist_to_bb == True:
            cli_print("WARNING: Depth calculation with raw output format is not supported! It's only supported for YOLO/mobilenet based NNs, disabling calc_dist_to_bb", PrintColors.WARNING)
            self.calc_dist_to_bb = False
        
        stream_names = [stream if isinstance(stream, str) else stream['name'] for stream in self.stream_list]
        if ('disparity' in stream_names or 'disparity_color' in stream_names) and self.calc_dist_to_bb == True:
            cli_print("WARNING: Depth calculation with disparity/disparity_color streams is not supported! Disabling calc_dist_to_bb", PrintColors.WARNING)
            self.calc_dist_to_bb = False

        # check for known bad configurations
        if 'depth' in stream_names and ('disparity' in stream_names or 'disparity_color' in stream_names):
            print('ERROR: depth is mutually exclusive with disparity/disparity_color')
            exit(2)

        if self.args['stereo_lr_check'] == True:
            raise ValueError("Left-right check option is still under development. Don;t enable it.")

        # Do not modify the default values in the config Dict below directly. Instead, use the `-co` argument when running this script.
        config = {
            # Possible streams:
            # ['left', 'right', 'jpegout', 'video', 'previewout', 'metaout', 'depth_sipp', 'disparity', 'depth_color_h']
            # If "left" is used, it must be in the first position.
            # To test depth use:
            # 'streams': [{'name': 'depth_sipp', "max_fps": 12.0}, {'name': 'previewout', "max_fps": 12.0}, ],
            'streams': self.args['streams'],
            'depth':
            {
                'calibration_file': consts.resource_paths.calib_fpath,
                'left_mesh_file': consts.resource_paths.left_mesh_fpath,
                'right_mesh_file': consts.resource_paths.right_mesh_fpath,
                'padding_factor': 0.3,
                'depth_limit_m': 10.0, # In meters, for filtering purpose during x,y,z calc
                'median_kernel_size': self.args['stereo_median_size'],
                'lr_check': self.args['stereo_lr_check'],
                'warp_rectify':
                {
                    'use_mesh' : self.args['use_mesh'], # if False, will use homography
                    'mirror_frame': self.args['mirror_rectified'] == 'true', # if False, the disparity will be mirrored instead
                    'edge_fill_color': 0, # gray 0..255, or -1 to replicate pixel values
                },
            },
            'ai':
            {
                'blob_file': blobMan.blob_file,
                'blob_file_config': blobMan.blob_file_config,
                'blob_file2': blobMan.blob_file2,
                'blob_file_config2': blobMan.blob_file_config2,
                'calc_dist_to_bb': self.calc_dist_to_bb,
                'keep_aspect_ratio': not self.args['full_fov_nn'],
                'camera_input': self.args['cnn_camera'],
                'shaves' : shave_nr,
                'cmx_slices' : cmx_slices,
                'NN_engines' : NCE_nr,
            },
            # object tracker
            'ot':
            {
                'max_tracklets'        : 20, #maximum 20 is supported
                'confidence_threshold' : 0.5, #object is tracked only for detections over this threshold
            },
            'board_config':
            {
                'swap_left_and_right_cameras': self.args['swap_lr'], # True for 1097 (RPi Compute) and 1098OBC (USB w/onboard cameras)
                'left_fov_deg': self.args['field_of_view'], # Same on 1097 and 1098OBC
                'rgb_fov_deg': self.args['rgb_field_of_view'],
                'left_to_right_distance_cm': self.args['baseline'], # Distance between stereo cameras
                'left_to_rgb_distance_cm': self.args['rgb_baseline'], # Currently unused
                'store_to_eeprom': self.args['store_eeprom'],
                'clear_eeprom': self.args['clear_eeprom'],
                'override_eeprom': self.args['override_eeprom'],
            },
            'camera':
            {
                'rgb':
                {
                    # 3840x2160, 1920x1080
                    # only UHD/1080p/30 fps supported for now
                    'resolution_h': self.args['rgb_resolution'],
                    'fps': self.args['rgb_fps'],
                },
                'mono':
                {
                    # 1280x720, 1280x800, 640x400 (binning enabled)
                    'resolution_h': self.args['mono_resolution'],
                    'fps': self.args['mono_fps'],
                },
            },
            'app':
            {
                'sync_video_meta_streams': self.args['sync_video_meta'],
                'sync_sequence_numbers'  : self.args['sync_sequence_numbers'],
                'usb_chunk_KiB' : self.args['usb_chunk_KiB'],
            },
            #'video_config':
            #{
            #    'rateCtrlMode': 'cbr', # Options: cbr / vbr
            #    'profile': 'h265_main', # Options: 'h264_baseline' / 'h264_main' / 'h264_high' / 'h265_main / 'mjpeg' '
            #    'bitrate': 8000000, # When using CBR (H264/H265 only)
            #    'maxBitrate': 8000000, # When using CBR (H264/H265 only)
            #    'keyframeFrequency': 30, (H264/H265 only)
            #    'numBFrames': 0, (H264/H265 only)
            #    'quality': 80 # (0 - 100%) When using VBR or MJPEG profile
            #}
            #'video_config':
            #{
            #    'profile': 'mjpeg',
            #    'quality': 95
            #}
        }

        self.jsonConfig = self.postProcessJsonConfig(config)