def main(): # Get a list of ALL the sticks that are plugged in # we need at least one devices = mvnc.EnumerateDevices() if len(devices) == 0: print('No NCS devices found') quit() # Pick the first stick to run the network device = mvnc.Device(devices[0]) # Open the NCS device.OpenDevice() # The graph file that was created with the ncsdk compiler graph_file_name = GRAPH_FILENAME # read in the graph file to memory buffer with open(graph_file_name, mode='rb') as f: graph_in_memory = f.read() # create the NCAPI graph instance from the memory buffer containing the graph file. graph = device.AllocateGraph(graph_in_memory) validated_image = cv2.imread(validated_image_filename) valid_output = run_inference(validated_image, graph) run_camera(valid_output, validated_image_filename, graph) # Clean up the graph and the device graph.DeallocateGraph() device.CloseDevice()
def main(): # Get a list of ALL the sticks that are plugged in # we need at least one devices = mvnc.EnumerateDevices() if len(devices) == 0: print('No NCS devices found') quit() # Pick the first stick to run the network device = mvnc.Device(devices[0]) # Open the NCS device.OpenDevice() # The graph file that was created with the ncsdk compiler graph_file_name = GRAPH_FILENAME # read in the graph file to memory buffer with open(graph_file_name, mode='rb') as f: graph_in_memory = f.read() # create the NCAPI graph instance from the memory buffer containing the graph file. graph = device.AllocateGraph(graph_in_memory) cap = cv2.VideoCapture(choose) while True: ret, validated_image = cap.read() gray_img = cv2.cvtColor(validated_image, cv2.COLOR_BGR2GRAY) if len(detector(gray_img, 1)) == 1: if ret == True: #validated_image = cv2.imread(validated_image_filename) valid_output = run_inference(validated_image, graph) # get list of all the .jpg files in the image directory input_image_filename_list = os.listdir(IMAGES_DIR) input_image_filename_list = [ i for i in input_image_filename_list if i.endswith('.jpg') ] if (len(input_image_filename_list) < 1): # no images to show print('No .jpg files found') return 1 run_images(valid_output, validated_image_filename, graph, input_image_filename_list) else: #Speak.tts_play("未检测到人脸") print("未检测人脸") # Clean up the graph and the device graph.DeallocateGraph() device.CloseDevice()
def main(): # name of the opencv window cv_window_name = "SSD MobileNet - hit any key to exit" # Get a list of ALL the sticks that are plugged in # we need at least one devices = mvnc.EnumerateDevices() if len(devices) == 0: print('No devices found') quit() # Pick the first stick to run the network device = mvnc.Device(devices[0]) # Open the NCS device.OpenDevice() # The graph file that was created with the ncsdk compiler graph_file_name = '/home/walle/pfe_movidius/model/ssd_caffe/graph' # read in the graph file to memory buffer with open(graph_file_name, mode='rb') as f: graph_in_memory = f.read() cam = cv2.VideoCapture(0) # create the NCAPI graph instance from the memory buffer containing the graph file. graph = device.AllocateGraph(graph_in_memory) # read the image to run an inference on from the disk infer_image = cv2.imread(IMAGE_FULL_PATH) _, infer_image = cam.read() # run a single inference on the image and overwrite the # boxes and labels run_inference(infer_image, graph) # display the results and wait for user to hit a key cv2.imshow(cv_window_name, infer_image) cv2.waitKey(1) # Clean up the graph and the device graph.DeallocateGraph() device.CloseDevice()
def __init__(self, graphPath, movidiusID=0): devices = mvnc.EnumerateDevices() if len(devices) == 0: logging.critical('No NCS devices found') quit() # Pick the first stick to run the network device = mvnc.Device(devices[movidiusID]) # Open the NCS device.OpenDevice() # read in the graph file to memory buffer with open(graphPath, mode='rb') as f: graph_in_memory = f.read() # create the NCAPI graph instance from the memory buffer containing the graph file. self.graph = device.AllocateGraph(graph_in_memory)
def main(): use_camera = True # Get a list of ALL the sticks that are plugged in # we need at least one devices = mvnc.EnumerateDevices() if len(devices) == 0: print('No NCS devices found') quit() # Pick the first stick to run the network device = mvnc.Device(devices[0]) # Open the NCS device.OpenDevice() # The graph file that was created with the ncsdk compiler graph_file_name = GRAPH_FILENAME # read in the graph file to memory buffer with open(graph_file_name, mode='rb') as f: graph_in_memory = f.read() # create the NCAPI graph instance from the memory buffer containing the graph file. graph = device.AllocateGraph(graph_in_memory) valid_output = [] for i in validated_image_list: validated_image = cv2.imread("./validated_images/"+i) #cv2.waitKey(0) valid_output.append(run_inference(validated_image, graph)) if (use_camera): run_camera(valid_output, validated_image_list, graph) else: input_image_filename_list = os.listdir(IMAGES_DIR) input_image_filename_list = [i for i in input_image_filename_list if i.endswith('.jpg')] if (len(input_image_filename_list) < 1): print('No .jpg files found') return 1 run_images(valid_output, validated_image_list, graph, input_image_filename_list) # Clean up the graph and the device graph.DeallocateGraph() device.CloseDevice()
def main(): connected_devices = mvnc.EnumerateDevices() if len(connected_devices) == 0: print("No NCS is detected") quit() primary_NCS = mvnc.Device(connected_devices[0]) primary_NCS.OpenDevice() with open(GRAPH_FILENAME, mode = "rb") as f: graph_in_memory = f.read() graph = primary_NCS.AllocateGraph(graph_in_memory) valid_output = [] for i in validated_image_list: valid_image = cv2.imread("./validated_images/"+i) valid_output.append(infer(valid_image, graph)) run_camera(valid_output, validated_image_list, graph) graph.DeallocateGraph() primary_NCS.CloseDevice()
def main(argv): parse_args(argv) Config.model_labels = parse_labels(Config.model_labels_file) Config.label_colors = get_label_colors(Config.model_labels) print_summary() # open video source cap = get_video(Config.source, Config.video_path) print("Video Properties:") print("Loaded {} video from source {}".format(Config.source, Config.video_path)) # get frame width/height actual_frame_width = cap.get(cv.CAP_PROP_FRAME_WIDTH) actual_frame_height = cap.get(cv.CAP_PROP_FRAME_HEIGHT) print("Video Resolution {} x {}".format(actual_frame_width, actual_frame_height)) # load NN model for platform if Config.platform == 'cpu': if Config.framework == 'caffe': net = cv.dnn.readNetFromCaffe(Config.model_file, Config.model_weight_file) elif Config.framework == 'tensorflow': net = cv.dnn.readNetFromTensorflow(Config.model_file, Config.model_weight_file) else: print("{} Framework not supported".format(Config.framework)) sys.exit(2) elif Config.platform == 'movidius': mvnc.SetGlobalOption(mvnc.GlobalOption.LOG_LEVEL, 2) # Get a list of ALL the sticks that are plugged in mv_devices = mvnc.EnumerateDevices() if len(mv_devices) == 0: print('No Movidius devices found') sys.exit(2) else: print('{} Movidius Device/s Found'.format(len(mv_devices))) # Pick the first stick to run the network movidius = mvnc.Device(mv_devices[0]) movidius.OpenDevice() with open(Config.model_weight_file, mode='rb') as f: graph_data = f.read() # allocate the Graph instance from NCAPI by passing the memory buffer movidius_graph = movidius.AllocateGraph(graph_data) else: print("{} Platform not supported".format(Config.platform)) print('-d, --device cpu|movidius : hw platform') sys.exit(2) # Start Counting frames to Calculate FPS frame_count = 0 start_time = time.time() inferred_frame_count = 0 cv.namedWindow("Real Time Object Detection", cv.WINDOW_FULLSCREEN) detections = None while True: # read frame from capture has_frame, frame = cap.read() if not has_frame: end_time = time.time() print("No more frame from from video source, exiting ....") break if Config.infer_frame_rate == -1 or inferred_frame_count / ( time.time() - start_time) < Config.infer_frame_rate: resized_frame = cv.resize( frame, (Config.model_image_height, Config.model_image_width)) if Config.platform == 'cpu': detections = infer_with_cpu(resized_frame, net) elif Config.platform == 'movidius': detections = infer_with_movidius(resized_frame, movidius_graph) else: print('Platform not found') sys.exit(2) inferred_frame_count += 1 if detections is not None: frame = post_process(frame, detections) # display text to let user know how to quit cv.rectangle(frame, (0, 0), (220, 60), (50, 50, 50, 100), -1) cv.putText(frame, "Q to Quit", (10, 12), cv.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1) cv.putText( frame, 'CPU Count: {} - CPU% : {} '.format(psutil.cpu_count(), process.cpu_percent()), (10, 35), cv.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1) cv.putText(frame, 'Inference Frame Rate: {}'.format(Config.infer_frame_rate), (10, 55), cv.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1) cv.imshow('Real Time Object Detection', frame) frame_count += 1 if cv.waitKey(Config.fps_delay) & 0xFF == ord('q'): end_time = time.time() break #TODO: UP Key to increase IPF , DOWN Key to decrease IPF frames_per_second = frame_count / (end_time - start_time) print('Calculated Frames Per Second: ' + str(frames_per_second)) cv.destroyAllWindows() # Release Movidius Device Allocation if Config.platform == 'movidius': movidius_graph.DeallocateGraph() movidius.CloseDevice() cap.release()
def main(): camModel = input("Please enter the camera model being used: ") file = open("FaceID_Test_Results-2F.txt", "a") file.write(camModel + "\n\n") file.close() connected_devices = mvnc.EnumerateDevices() if len(connected_devices) == 0: print("No NCS is detected") quit() primary_NCS = mvnc.Device(connected_devices[0]) primary_NCS.OpenDevice() with open(GRAPH_FILENAME, mode="rb") as f: graph_in_memory = f.read() graph = primary_NCS.AllocateGraph(graph_in_memory) valid_output = [] for i in validated_image_list: valid_image = cv2.imread("./validated_images/" + i) valid_output.append(infer(valid_image, graph)) p360_H = 360 p360_W = 480 p480_H = 480 p480_W = 640 p720_H = 720 p720_W = 1280 p1080_H = 1080 p1080_W = 1920 faceID_H = 640 faceID_W = 512 network_Res = 160 camera = cv2.VideoCapture(1) testName = "360p Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, p360_W) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, p360_H) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "480p Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, p480_W) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, p480_H) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "720p Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, p720_W) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, p720_H) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "1080p Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, p1080_W) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, p1080_H) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "360p Rotated Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, p360_H) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, p360_W) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "480p Rotated Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, p480_H) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, p480_W) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "720p Rotated Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, p720_H) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, p720_W) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "1080p Rotated Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, p1080_H) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, p1080_W) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "FaceID Standard Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, faceID_W) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, faceID_H) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "FaceID High Res Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, faceID_W * 2) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, faceID_H * 2) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "FaceID Low Res Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, faceID_W / 2) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, faceID_H / 2) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "FaceID Rotated Standard Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, faceID_H) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, faceID_W) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "FaceID Rotated High Res Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, faceID_H * 2) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, faceID_W * 2) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "FaceID Rotated Low Res Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, faceID_H / 2) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, faceID_W / 2) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() testName = "Network Test" camera.set(cv2.CAP_PROP_FRAME_WIDTH, network_Res) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, network_Res) cv2.namedWindow(testName) runTest(valid_output, validated_image_list, graph, camera, testName) cv2.destroyAllWindows() file = open("FaceID_Test_Results-2F.txt", "a") notes = input("Enter any notes: ") file.write("\n" + notes) file.write( "\n\n ------------------------------------------------------- \n") file.close() camera.release() graph.DeallocateGraph() primary_NCS.CloseDevice()
def main(): global graph_filename, resize_output, resize_output_width, resize_output_height if (len(argv) < 2): print("No Graph is provided") print_usage() return 1 if (not handle_args()): print_usage() return 1 # configure the NCS mvnc.SetGlobalOption(mvnc.GlobalOption.LOG_LEVEL, 2) # Get a list of ALL the sticks that are plugged in devices = mvnc.EnumerateDevices() if len(devices) == 0: print('No devices found') quit() # Pick the first stick to run the network device = mvnc.Device(devices[0]) # Open the NCS device.OpenDevice() #graph_filename = sys.argv[1] #graph_filename = '/home/saikrishnas/workSpace/Traffic_sign_Dt/inference_graph_ssd_inception_47classes/graph' # Load graph file to memory buffer with open(graph_filename, mode='rb') as f: graph_data = f.read() # allocate the Graph instance from NCAPI by passing the memory buffer ssd_mobilenet_graph = device.AllocateGraph(graph_data) cv2.namedWindow(cv_window_name) cv2.moveWindow(cv_window_name, 10, 10) exit_app = False while (True): cap = cv2.VideoCapture("./traffic_sign2.mp4") actual_frame_width = cap.get(cv2.CAP_PROP_FRAME_WIDTH) actual_frame_height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) print('actual video resolution: ' + str(actual_frame_width) + ' x ' + str(actual_frame_height)) if ((cap == None) or (not cap.isOpened())): print('Could not open video device. Make sure file exists:') print('file name:' + input_video_file) print('Also, if you installed python opencv via pip or pip3 you') print( 'need to uninstall it and install from source with -D WITH_V4L=ON' ) print('Use the provided script: install-opencv-from_source.sh') exit_app = True break frame_count = 0 start_time = time.time() end_time = start_time while (True): ret, display_image = cap.read() if (not ret): end_time = time.time() print("No image from from video device, exiting") break # check if the window is visible, this means the user hasn't closed # the window via the X button prop_val = cv2.getWindowProperty(cv_window_name, cv2.WND_PROP_ASPECT_RATIO) if (prop_val < 0.0): end_time = time.time() exit_app = True break run_inference(display_image, ssd_mobilenet_graph) if (resize_output): display_image = cv2.resize( display_image, (resize_output_width, resize_output_height), cv2.INTER_LINEAR) cv2.imshow(cv_window_name, display_image) raw_key = cv2.waitKey(1) if (raw_key != -1): if (handle_keys(raw_key) == False): end_time = time.time() exit_app = True break frame_count += 1 frames_per_second = frame_count / (end_time - start_time) print('Frames per Second: ' + str(frames_per_second)) cap.release() if (exit_app): break # Clean up the graph and the device ssd_mobilenet_graph.DeallocateGraph() device.CloseDevice() cv2.destroyAllWindows()
def __init__(self): super(PeopleDetectionNode, self).__init__() # init the node rospy.init_node('people_object_detection', anonymous=False) rospy.loginfo("Starting NCS People detecter...") # Get parameters from launch file network_graph_path = rospy.get_param('~network_graph_path', "") #confirm path to ssd_mobilenet_graph file was supplied if network_graph_path: rospy.loginfo('Found network_graph_path: ' + network_graph_path) else: rospy.logerr("network_graph_path param is required!") quit() # NOTE: We use the 'ncappzoo/apps/video_objects/graph', local copy stored at: # '.../ncs_people_detection/network_graphs/ssd_mobilenet_graph' # Get other parameters from YAML file camera_rgb_topic = rospy.get_param("~camera_rgb_topic", "/cv_camera/image_raw") camera_depth_topic = rospy.get_param("~camera_depth_topic", "") video_file_path = rospy.get_param("~video_file_path", "") self.show_cv_debug_window = False self.show_cv_debug_window = rospy.get_param("~show_cv_debug_window", False) self.incoming_image_msg = None self.incoming_depth_msg = None self.cv_image = None self._bridge = CvBridge() self.skip_frame_count = 0 # Advertise the result of Object Detector (COB format) self.pub_detections = rospy.Publisher('/object_detection/detections', \ DetectionArray, queue_size=1) # and the marked up image self.pub_detections_image = rospy.Publisher(\ '/object_detection/detections_image', Image, queue_size=1) # Advertise the BodyTracker message (same as Nuitrack node) self.pub_body_tracker = rospy.Publisher('/body_tracker/position', \ BodyTracker, queue_size=1) # Advertise the BodyTrackerArray message (same as Nuitrack node, but an array!) self.pub_body_tracker_array = rospy.Publisher('/body_tracker_array/position', \ BodyTrackerArray, queue_size=1) # configure the NCS mvnc.SetGlobalOption(mvnc.GlobalOption.LOG_LEVEL, 2) # Get a list of ALL the sticks that are plugged in devices = mvnc.EnumerateDevices() if len(devices) == 0: rospy.logerr('*** No Movidius NCS devices found! Exiting! ***') quit() # Pick the first stick to run the network device = mvnc.Device(devices[0]) # Open the NCS device.OpenDevice() # Load graph file to memory buffer with open(network_graph_path, mode='rb') as f: graph_data = f.read() # allocate the Graph instance from NCAPI by passing the memory buffer self.ssd_mobilenet_graph = device.AllocateGraph(graph_data) # open the camera or video file if not video_file_path or video_file_path == "no" or video_file_path == "cam": # Subscribe to the live video messages if camera_depth_topic: # When depth is specified, synchronize RGB and Depth frames # warning! if used, but no depth camera, RGB will never show up! # Subscribe to approx synchronized rgb and depth frames self.sub_rgb = message_filters.Subscriber( camera_rgb_topic, Image) self.sub_depth = message_filters.Subscriber( camera_depth_topic, Image) # Create the message filter ts = message_filters.ApproximateTimeSynchronizer(\ [self.sub_rgb, self.sub_depth], 2, 0.9) ts.registerCallback(self.rgb_and_depth_callback) rospy.loginfo('Subscribing to SYNCHRONIZED RGB: ' + \ camera_rgb_topic + " and Depth: " + camera_depth_topic) else: # no depth topic, RGB only self.sub_rgb = rospy.Subscriber(camera_rgb_topic,\ Image, self.rgb_callback, queue_size=1, buff_size=2**24) rospy.loginfo('Subscribing to camera_rgb_topic: ' + camera_rgb_topic) else: rospy.logwarn("READING FROM VIDEO FILE INSTEAD OF ROS MESSAGES") self.read_from_video(video_file_path) # spin rospy.spin()
def main(): global resize_output, resize_output_width, resize_output_height if (not handle_args()): print_usage() return 1 # configure the NCS mvnc.SetGlobalOption(mvnc.GlobalOption.LOG_LEVEL, 2) # Get a list of ALL the sticks that are plugged in devices = mvnc.EnumerateDevices() if len(devices) == 0: print('No devices found') quit() # Pick the first stick to run the network device = mvnc.Device(devices[0]) # Open the NCS device.OpenDevice() graph_filename = 'graph' # Load graph file to memory buffer with open(graph_filename, mode='rb') as f: graph_data = f.read() # allocate the Graph instance from NCAPI by passing the memory buffer ssd_mobilenet_graph = device.AllocateGraph(graph_data) # get list of all the .mp4 files in the image directory # input_video_filename_list = os.listdir(input_video_path) # input_video_filename_list = [i for i in input_video_filename_list if i.endswith('.mp4')] # if (len(input_video_filename_list) < 1): # # no images to show # print('No video (.mp4) files found') # return 1 cv2.namedWindow(cv_window_name) cv2.moveWindow(cv_window_name, 10, 10) cap = cv2.VideoCapture(CAMERA_INDEX) cap.set(cv2.CAP_PROP_FRAME_WIDTH, REQUEST_CAMERA_WIDTH) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, REQUEST_CAMERA_HEIGHT) actual_frame_width = cap.get(cv2.CAP_PROP_FRAME_WIDTH) actual_frame_height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) print('actual video resolution: ' + str(actual_frame_width) + ' x ' + str(actual_frame_height)) if ((cap == None) or (not cap.isOpened())): print('Could not open camera. Make sure it is plugged in.') # print ('file name:' + input_video_file) print('Also, if you installed python opencv via pip or pip3 you') print( 'need to uninstall it and install from source with -D WITH_V4L=ON') print('Use the provided script: install-opencv-from_source.sh') exit_app = True return exit_app = False while (True): #for input_video_file in input_video_filename_list : # cap = cv2.VideoCapture(input_video_file) frame_count = 0 start_time = time.time() end_time = start_time while (True): ret, display_image = cap.read() if (not ret): end_time = time.time() print("No image from from video device, exiting") break # check if the window is visible, this means the user hasn't closed # the window via the X button prop_val = cv2.getWindowProperty(cv_window_name, cv2.WND_PROP_ASPECT_RATIO) if (prop_val < 0.0): end_time = time.time() exit_app = True break run_inference(display_image, ssd_mobilenet_graph) if (resize_output): display_image = cv2.resize( display_image, (resize_output_width, resize_output_height), cv2.INTER_LINEAR) cv2.imshow(cv_window_name, display_image) raw_key = cv2.waitKey(1) if (raw_key != -1): if (handle_keys(raw_key) == False): end_time = time.time() exit_app = True break frame_count += 1 frames_per_second = frame_count / (end_time - start_time) print('Frames per Second: ' + str(frames_per_second)) cap.release() if (exit_app): break if (exit_app): break # Clean up the graph and the device ssd_mobilenet_graph.DeallocateGraph() device.CloseDevice() cv2.destroyAllWindows()
import mvnc_simple_api as mvnc import numpy import cv2 path_to_networks = './' path_to_images = './' graph_filename = 'graph' image_filename = "rose.jpg" #path_to_images + 'nps_electric_guitar.png' #mvnc.SetGlobalOption(mvnc.GlobalOption.LOGLEVEL, 2) devices = mvnc.EnumerateDevices() if len(devices) == 0: print('No devices found') quit() device = mvnc.Device(devices[0]) device.OpenDevice() #Load graph with open(path_to_networks + graph_filename, mode='rb') as f: graphfile = f.read() #Load preprocessing data mean = 128 std = 1.0 / 128.0 #Load categories categories = [] with open(path_to_networks + 'categories.txt', 'r') as f: for line in f: cat = line.split('\n')[0]
def main(): connected_devices = mvnc.EnumerateDevices() if len(connected_devices) == 0: print("No NCS is detected") quit() primary_NCS = mvnc.Device(connected_devices[0]) primary_NCS.OpenDevice() with open(GRAPH_FILENAME, mode="rb") as f: graph_in_memory = f.read() graph = primary_NCS.AllocateGraph(graph_in_memory) valid_output = [] for i in validated_image_list: valid_image = cv2.imread("./validated_images/" + i) valid_output.append(infer(valid_image, graph)) with open('timing_and_accuracy_analysis.csv', 'w', newline='') as csvfile: csvw = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL) csvw.writerow([ "Resolution;Test;Total Frames;Detected Frames;Assurance;Average Assurance;Average Read Time;Average Cascade Time;Average Neural Time;Average Match Time;Average Show Time;Average Cycle Time No Face;Average Cycle Time One Face;Average Cycle Time Two Face;Average Cycle Time Three Face" ]) run_camera(valid_output, validated_image_list, graph, csvw, 640, 480, "3ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 1280, 720, "3ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 1920, 1080, "3ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 640, 480, "5ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 1280, 720, "5ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 1920, 1080, "5ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 640, 480, "10ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 1280, 720, "10ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 1920, 1080, "10ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 640, 480, "15ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 1280, 720, "15ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 1920, 1080, "15ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 640, 480, "20ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 1280, 720, "20ft_test.mp4") run_camera(valid_output, validated_image_list, graph, csvw, 1920, 1080, "20ft_test.mp4") cv2.destroyAllWindows() graph.DeallocateGraph() primary_NCS.CloseDevice()