コード例 #1
0
    def fetchFrame(camera):
        logger = logging.getLogger(__name__)

        try:
            device = AmcrestCamera(host= camera.ip_address, port = 80, user = camera.username, password =camera.password).camera
            cwd = os.getcwd()
            img_path = '/Images/' + camera.short_name + '.png'  
            full_path =cwd +img_path 
            request = device.snapshot(path_file = full_path)
            if request._fp_bytes_read <1000:  
                os.remove(full_path)
                raise AmcrestError            
            del device
            return img_path

        except AmcrestError:
            camera_source = '/Images/cam_not_found.png'
            logging.error("Camera Error: "+ camera.short_name)
            return camera_source
        except:
            path = "/Images/int_error.png"
            return path
コード例 #2
0
# http://admin:[email protected]/cgi-bin/devAudioInput.cga?action=getCollect

# works
# http://admin:[email protected]/cgi-bin/configManager.cgi?action=getConfig&name=Snap

data = {'username': '******', 'password': '******'}

error_count = 0
success_count = 0
for i in range(5):
    start_time = time.time()
    print(start_time)

    try:
        response = camera.snapshot(0)
        print(i, "success", time.time() - start_time)
        success_count = success_count + 1
        img_bytes = response.read()
        img_array = Image.open(io.BytesIO(img_bytes))
        img_numpy = numpy.array(img_array)
        img_bgr = cv2.cvtColor(img_numpy, cv2.COLOR_RGB2BGR)
        print(img_bgr.shape)
        cv2.imshow('Amcrest', img_bgr)
    except:
        print(i, "error")
        error_count = error_count + 1

    # time.sleep(1)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break