Skip to main content

Camera service grpc api (for python3.7 )

Project description

Camera service grpc API

Install

  1. using pip install local package
pip install camera-service-api

Dependencies

  • grpcio 1.63.0
  • protobuf 5.26.1

API

Get API Instance create_camera_service_api

  • host , camera server host , e.g. localhost
  • port , camera server port , e.g. 6000
# host 
api = create_camera_service_api(host, port)

Get All camera meta infos get_camera_metas

def get_camera_metas(self) -> List[CameraMeta]:
    ...     
metas = api.get_camera_metas()
for meta in metas:
    print(f"Camera modelName: {meta.modelName} - deviceVersion: {meta.deviceVersion}")
    print("get camera image serialNumber ", meta.serialNumber)
    print("get info ", meta.info)

CameraMeta

  • cameraType , camera type , GIGE | u3v
  • serialNumber : camera serial number ,
  • modelName : model name
  • manufactureName : manufacture name
  • deviceVersion : device version
  • userDefinedName : name defined by user
  • info : Map[string,string] , ext info

Get live image by serial number

input camera serial number and return live image (jpg), bytes. and if return None means the camera maybe offline.

and using try .. except for catch exception

def get_image(self, sn: str) -> bytes:
    ...     

Example:

...
body = api.get_image(meta.serialNumber)
print(" body : ", len(body)  )

...

fopen = open('test.jpg', 'wb+')
fopen.write( body )
fopen.close()

...

Example

import time

import grpc

from services.cameras.camera_service_api import create_camera_service_api


max_test = 100

def test_camera_api(host, port):
    #
    api = create_camera_service_api(host, port)
    metas = api.get_camera_metas()
    for meta in metas:
        print(f"Camera modelName: {meta.modelName} - deviceVersion: {meta.deviceVersion}")
        print("get camera image serialNumber ", meta.serialNumber)
        print("get info ", meta.info)

        t1 = time.time()
        try:

            for i in range( max_test ):
                body = api.get_image(meta.serialNumber)
                print(" body : ", i, len(body)  )

        except Exception as e:
            print( e) 

        t2 = time.time()
        tt = t2-t1
        avg = tt / max_test
        print( f" Try {max_test} times get image , using {tt} , avg {avg} ")

        # fopen = open('body.jpg'.encode('utf-8'), 'wb+')
        # fopen.write( body, )
        # fopen.close()

# protect the entry point
if __name__ == '__main__':
    print("GRPC Version : {} ".format(grpc.__version__))
    test_camera_api("127.0.0.1", 6000)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

camera-service-api-1.1.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

camera_service_api-1.1.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file camera-service-api-1.1.1.tar.gz.

File metadata

  • Download URL: camera-service-api-1.1.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.9

File hashes

Hashes for camera-service-api-1.1.1.tar.gz
Algorithm Hash digest
SHA256 2b95380413ca600afcd9e3de907acb1487f132ab5919b851f8a4024942a71c2e
MD5 f99d6bb7265cdefc5eaadf061827863e
BLAKE2b-256 0e88abce7e3561b15211858dd044f9900edcb84a67497494aee0fd776674cf7f

See more details on using hashes here.

File details

Details for the file camera_service_api-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for camera_service_api-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 74a1be757038b491ada34db67f22ff9b8c448d86f0f77430dae19452c18253df
MD5 0f6763fe569f6769d312737d5aecb095
BLAKE2b-256 90d0c5d9a5b93ec6a25fde3648b2bc05607ebfa8f8612af6fbecbea5219541e6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page