Camera service grpc api
Project description
Camera service grpc API
Install Camerm api
Install
- using pip install local package
# Python12
pip install camera-service-api==1.1.0
# Python7
pip install camera-service-api==1.1.1
Dependencies
- grpcio 1.63.0
- protobuf 5.26.1
Build by proto
pip install grpcio grpcio-tools protobuf
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.8.tar.gz
(12.3 kB
view details)
Built Distribution
File details
Details for the file camera_service_api-1.1.8.tar.gz
.
File metadata
- Download URL: camera_service_api-1.1.8.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e407b6e9baacafc0fd4562e298d2abd7fa99f0b70dbec3731f94acf8a68609b |
|
MD5 | 71405e04967e4d0f35662ec9c45e9ec0 |
|
BLAKE2b-256 | 1b635e9482c036092b74c94e10de4c138502047dec12edac072b91ecd5a7ed7d |
File details
Details for the file camera_service_api-1.1.8-py3-none-any.whl
.
File metadata
- Download URL: camera_service_api-1.1.8-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 899ae192258f21bb072828b804287ea2687234e7a0b7e3dcf3ed18e8d43e4006 |
|
MD5 | e4b4157e5bff4279cd2a82a9132f8361 |
|
BLAKE2b-256 | 069f4be41aa6d18ebd27debd216803bfe350eb55878ed1d775e4ebfe1611a421 |