Esempio n. 1
0
def main(protocol=None):
    print("\nPython %s\n" % sys.version)
    print("IoT Hub Client for Python")

    #generate a new folder based on time and then copy into that folder ....

    with CameraClient.Connect() as camera_client:

        # starting camera (this starts the preview RTSP stream)
        camera_client.set_preview_mode(True)
        print(
            "Start VLC Media player and watch the live rtsp stream for 60 secs"
        )  #need to extract the stream address and display here
        #utility.transferdlc()
        #time.sleep(4)
        #Setting dlc file path

        #Loading your model to hardware for inferencing and getting results

        #camera_client.setVAM_Rule(True,"FR")
        camera_client.loadVAM("MD")

        print(
            "The sample is now waiting for messages and will indefinitely.  Press ctrl-C to exit. "
        )
        time.sleep(10)

        hub_manager = iot.HubManager()
        while (True):
            #hub_manager.SendMsgToCloud("Hallo from module!!!")
            time.sleep(10)
Esempio n. 2
0
def sendMsgToCloud(message):
    try:
        #hub_manger.forward_event_to_output("output1", message, 0)
        myhub_manager = iot.HubManager()
        myhub_manager.SendSimulationData(message)
        time.sleep(5)
    except Exception:
        logger.exception("exception occured!!")
        pass
def main(protocol=None):
    print("\nPython %s\n" % sys.version)
    parser = argparse.ArgumentParser()
    parser.add_argument('--ip',
                        help='ip address of the camera',
                        default=utility.getWlanIp())
    parser.add_argument('--username',
                        help='username of the camera',
                        default='admin')
    parser.add_argument('--password',
                        help='password of the camera',
                        default='admin')
    args = parser.parse_args()
    ip_addr = args.ip
    username = args.username
    password = args.password
    ip_addr = '127.0.0.1'
    hub_manager = iot.HubManager()

    with CameraClient.connect(ip_address=ip_addr,
                              username=username,
                              password=password) as camera_client:
        #transferring model files to device
        utility.transferdlc()

        print(camera_client.configure_preview(display_out=1))

        camera_client.toggle_preview(True)
        time.sleep(15)
        rtsp_ip = utility.getWlanIp()
        rtsp_stream_addr = "rtsp://" + rtsp_ip + ":8900/live"
        hub_manager.iothub_client_sample_run(rtsp_stream_addr)

        camera_client.toggle_vam(True)

        camera_client.configure_overlay("inference")

        camera_client.toggle_overlay(True)
        try:
            with camera_client.get_inferences() as results:
                print_inferences(hub_manager, results)
        except KeyboardInterrupt:
            print("Stopping")
        try:
            print("inside infinite loop now")
            #while(True):
            #time.sleep(2)
        except KeyboardInterrupt:
            print("Stopping")

        camera_client.toggle_overlay(False)

        camera_client.toggle_vam(False)

        camera_client.toggle_preview(False)
Esempio n. 4
0
def main(protocol=None):
    print("\nPython %s\n" % sys.version)
    parser = argparse.ArgumentParser()
    parser.add_argument('--ip', help='ip address of the camera', default=utility.getWlanIp())
    parser.add_argument('--username', help='username of the camera', default='admin')
    parser.add_argument('--password', help='password of the camera', default='admin')
    args = parser.parse_args()
    ip_addr = args.ip
    username = args.username
    password = args.password
    ip_addr = '127.0.0.1'
    #ip_addr = '10.104.68.189' #remote
    hub_manager = iot.HubManager()

    with CameraClient.connect(ip_address=ip_addr, username=username, password=password) as camera_client:
        #transferring model files to device
        utility.transferdlc()

        print(camera_client.configure_preview(display_out=1))
        camera_client.toggle_preview(True)

        time.sleep(15)
        rtsp_ip = utility.getWlanIp()
        rtsp_stream_addr = "rtsp://" + rtsp_ip + ":8900/live"
        hub_manager.iothub_client_sample_run(rtsp_stream_addr)

        camera_client.toggle_vam(True)
        print("Completed toggle_vam in main")
        camera_client.configure_overlay("inference")
        print("Completed configure overlay in main")
        camera_client.toggle_overlay(True)
        print("Completed toggle_overlay in main")
        #firstImage = camera_client.captureimage()
        #print("First Image from main connection: ", firstImage)
        try: #uses instance of camera_client, to start reading stream of metadata and parse into data.
            with camera_client.get_inferences() as results:
                print_inferences(hub_manager, camera_client, results)

        except KeyboardInterrupt:
            print("Stopping")
        try:
            print("inside infinite loop now")
            #while(True):
                #time.sleep(2)
        except KeyboardInterrupt:
            print("Stopping")

        camera_client.toggle_overlay(False)

        camera_client.toggle_vam(False)

        camera_client.toggle_preview(False)
def main(protocol=None):
    #while(True):
    #time.sleep(1)
    logging.debug("\nPython %s\n" % sys.version)
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-p',
        '--pushmodel',
        help=
        'sets whether to push the model and required files to device or not',
        default=False)
    parser.add_argument('--ip',
                        help='ip address of the camera',
                        default=utility.getWlanIp())
    parser.add_argument('--username',
                        help='username of the camera',
                        default='admin')
    parser.add_argument('--password',
                        help='password of the camera',
                        default='admin')
    args = parser.parse_args()
    if args.pushmodel is not None:
        mypushmodel = args.pushmodel
        logging.debug("setting value from argu -p pushmodel to :: %s" %
                      mypushmodel)
    ip_addr = args.ip
    username = args.username
    password = args.password

    #getting Iot hub sdk ready with hub manager
    hub_manager = iot.HubManager()
    logging.debug("value of restartCamera is :: " + str(iot.restartCamera))
    #Connecting to camer using ipcWebServer SDK and turing camera on and then starting inferencing
    with CameraClient.connect(ip_address=ip_addr,
                              username=username,
                              password=password) as camera_client:
        #transferring model files to camera for inferencing
        utility.transferdlc(mypushmodel)

        #this call we set the camera to dispaly over HDMI
        logging.debug(
            camera_client.configure_preview(resolution="1080P",
                                            encode="AVC/H.264",
                                            bitrate="1.5Mbps",
                                            display_out=1))
        # this call turns on the camera and start transmetting over RTSP and HDMI a stream from camera
        camera_client.set_preview_state("on")

        #rtsp stream address
        rtsp_stream_addr = str(camera_client.preview_url)
        logging.debug("rtsp stream is :: " + rtsp_stream_addr)
        #uploading rtsp stream address to iot hub as twin property so that user one can know what there rtsp address is and then use it on vlc media player
        hub_manager.iothub_client_sample_run(rtsp_stream_addr)

        #Vam(Video analytics engine ) this will take the model and run on thee device
        camera_client.set_analytics_state("on")
        logging.debug(camera_client.vam_url)

        # this will set the frames to be overlayed with information recieved from inference results ffrom your model
        camera_client.configure_overlay("inference")

        #Turning overlay to Truse to see inferencing frame overlayed with inference results
        camera_client.set_overlay_state("on")

        try:
            with camera_client.get_inferences() as results:
                threadForPrint = threading.Thread(target=print_inferences,
                                                  args=(
                                                      results,
                                                      camera_client,
                                                      hub_manager,
                                                  ))
                print(" Staring thread to print inference results ")
                threadForPrint.start()
                print(" After thread start ....")
                #print_inferences(results,camera_client,hub_manager)
                print("!!!Getting infinite loop now!!!")
                while (True):
                    print(" inside loop now....")
                    if iot.restartCamera:
                        logging.info("iot.restartCamera ::" +
                                     str(iot.restartCamera))

                        restartInference(camera_client, hub_manager)
                        threadForPrint.join()
                        results = camera_client.get_inferences()
                        threadForPrint = threading.Thread(
                            target=print_inferences,
                            args=(results, camera_client, hub_manager))
                        print(" Staring thread to print inference results ")
                        threadForPrint.start()
                        """with camera_client.get_inferences() as results:
                            threadForPrint = threading.Thread(target=print_inferences, args=(results,camera_client,hub_manager))
                            print(" Staring thread to print inference results ")
                            threadForPrint.start()
                            print(" After thread start ....") """
                    time.sleep(1)
        except KeyboardInterrupt:
            logging.debug(
                "Failed in Main after switching model restarting camera ...")
            restartCam(camera_client, hub_manager)

        # turning everything off and logging out ...
        camera_client.set_overlay_state("off")

        camera_client.set_analytics_state("off")

        camera_client.set_preview_state("off")