Пример #1
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'
    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)
Пример #2
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)
Пример #3
0
    def __init__(self,
                 ip_address=None,
                 port=None,
                 username=None,
                 password=None,
                 session_token=None):
        if ip_address is None:
            #ip_address = '127.0.0.1'
            ip_address = utility.getWlanIp()
            #ip_address = '172.17.0.1'

        if port is None:
            port = '1080'

        if username is None:
            username = '******'

        if password is None:
            password = '******'

        self.username = username
        self.password = password
        self.ip_address = ip_address
        self.port = port
        self.session_token = session_token
Пример #4
0
 def set_preview_mode(self, status):
     path = "/preview"
     payload = {'switchStatus': status}
     response = self.connection.post(path, payload)
     if (response):
         #This starts a rtsp stream over a local area network
         # We are sending the rtsp address to iotedge device twin for user to copy and start streaming
         rtsp_stream_addr = "rtsp://" + utility.getWlanIp() + ":8900/live"
         #utility.sendMsgToTwin(rtsp_stream_addr)
     return response
def restartCam(camera_client=None, hub_manager=None):
    try:
        iot.restartCamera = False
        # turning everything off and logging out ...
        camera_client.logout()
        if camera_client is not None:
            camera_client = None

        utility.CallSystemCmd("systemctl restart qmmf-webserver")
        time.sleep(1)
        utility.CallSystemCmd("systemctl restart ipc-webserver")
        time.sleep(1)
        ip_addr = utility.getWlanIp()
        with CameraClient.connect(ip_address=ip_addr,
                                  username='******',
                                  password='******') as camera_client:
            #this call we set the camera to dispaly over HDMI
            #logging.debug(camera_client.configure_preview(resolution="1080P",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")
            #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")

            # heer we will use gstreamer to get the inference results from camera into thsi module and then send them up to cloud or another module
            try:
                with camera_client.get_inferences() as results:
                    print_inferences(results, camera_client, hub_manager)
            except KeyboardInterrupt:
                logging.debug("Stopping")
            try:
                logging.debug("inside infinite loop now")
                while (True):
                    time.sleep(2)
            except KeyboardInterrupt:
                logging.debug("Stopping")
    except:
        logging.debug(
            "we have got issue during Logout and Login restarting camera  ")
        utility.CallSystemCmd("systemctl restart")

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

    camera_client.set_analytics_state("off")

    camera_client.set_preview_state("off")
def capture_train():
    print("\nPython %s\n" % sys.version)
    parser = argparse.ArgumentParser()
    parser.add_argument('-t', '--tags', nargs='+', type=str, dest='tags', action='append', help='please input tag name')
    parser.add_argument('-n', '--nums', nargs='+', type=int, dest='nums', action='append', help='please input numbers of images to capture')
    parser.add_argument('-p','--pushmodel', help ='sets whether to push the model and required files to device or not', default=True)
    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.tags is not None:
        tags = [str(tag) for tag in args.tags]
        print("setting value from argu -t tags to :: %s" % args.tags)
        print(tags[0][0])
    tag_len = len(args.tags[0])
    print(tag_len)
    if args.nums is not None:
        nums = [str(n) for n in args.nums]
        print("numbers: %d", args.nums)
        print(nums[0][0])
    array_len = len(args.nums[0])
    if args.pushmodel is not None:
        mypushmodel = args.pushmodel
        print("setting value from argu -p pushmodel to :: %s" % mypushmodel)
    ip_addr = args.ip
    username = args.username
    password = args.password

    # Please change this address to camer ip address can be found by using adb shell -> ifconfig
    # ip_addr = 'localhost'
    with CameraClient.connect(ip_address=ip_addr, username=username, password=password) as camera_client:
        # camera_client.set_preview_state("off")
        # this call we set the camera to dispaly over HDMI
        print(camera_client.configure_preview(resolution="1080P",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_addr = str(camera_client.preview_url)
        print("rtsp stream is :: " + rtsp_stream_addr)
        camera_client.configure_overlay("text", "background images ...")
        camera_client.set_overlay_state("on")
        #capture(camera_client, nums=args.nums[0][0], tag='background')
        camera_client.set_overlay_state("off")
        for i in range(array_len):
            #print("array_len: " + str(array_len))
            camera_client.configure_overlay("text", str(args.tags[0][i]) + " images ...")
            camera_client.set_overlay_state("on")
            wait(args.tags[0][i])
            capture(camera_client, nums=int(args.nums[0][i]), tag=args.tags[0][i])
            camera_client.set_overlay_state("off")
Пример #7
0
def init(protocol=None):
    global PUSH_MODEL
    logging.info("\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',type=bool, 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.info("setting value from args.pushmodel :: %s" % args.pushmodel)
        logging.info("setting value from argu -p pushmodel to :: %s" % mypushmodel) """

    ip_addr = args.ip
    username = args.username
    password = args.password
    try:
        #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:

            #getting Iot hub sdk ready with hub manager
            hub_manager = HubManager(camera_client)
            #transferring model files to camera for inferencing
            utility.transferdlc(PUSH_MODEL)
            #this call we set the camera to dispaly over HDMI
            logging.info(
                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
            camera_client.set_preview_state("on")
            # setting camera handler that we will use to sync camera and IoT Hub
            #camera_handler = CameraIoTHandler(camera_client)
            #rtsp stream address
            rtsp_stream_addr = str(camera_client.preview_url)
            logging.info("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
            if (not camera_client.vam_running):
                camera_client.set_analytics_state("on")
            logging.info(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 True to see inferencing frame overlayed with inference results
            camera_client.set_overlay_state("on")
            # heer we will use gstreamer to get the inference results from camera into thsi module and then send them up to cloud or another module
            try:
                while (True):
                    with camera_client.get_inferences() as results:
                        print_inferences(results, camera_client, hub_manager)
                        print("Restarting get inference and print again!!!")
                    time.sleep(2)
            except KeyboardInterrupt:
                logging.debug("Stopping")

            # turning everything off and logging out ...

            camera_client.set_overlay_state("off")
            camera_client.set_analytics_state("off")
            camera_client.set_preview_state("off")
            #Vam(Video analytics machine) this will take the model and run on the device

    except Exception as e:
        logging.info(
            "Encountered an issue during camera intialization; restarting camera now."
        )
        logging.info(
            "Clearing all models and using the container default model configuration."
        )
        utility.transferdlc(True)
        #send_system_cmd("systemctl reboot")
        logging.exception(e)
        raise
Пример #8
0
def main(protocol=None):
    print("\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=True)
    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
        print("setting value from argu -p pushmodel to :: %s" % mypushmodel)
    ip_addr = args.ip
    username = args.username
    password = args.password

    #Please change this address to camer ip address can be found by using adb shell -> ifconfig
    ip_addr = '192.168.0.103'
    #hub_manager = iot.HubManager()
    #utility.transferdlc()
    with CameraClient.connect(ip_address=ip_addr,
                              username=username,
                              password=password) as camera_client:

        #this call we set the camera to dispaly over HDMI
        print(
            camera_client.configure_preview(resolution="1080P", 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)
        print("rtsp stream is :: " + rtsp_stream_addr)

        if not camera_client.captureimage():
            print("captureimage failed")
        #Vam(Video analytics engine ) this will take the model and run on thee device
        camera_client.set_analytics_state("on")
        print(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")

        # heer we will use gstreamer to get the inference results from camera into thsi module and then send them up to cloud or another module
        try:
            with camera_client.get_inferences() as results:
                print_inferences(results, camera_client)
        except:
            print("Stopping")
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")