Package: remio
REMIODocumentation|LicenseTable of ContentsIntroductionFeaturesInstallationDevelopmentSimplejpeg APISimple MJPEG ServerMultiple Cameras APIMultiple Serial APIExamplesIntroductionREMIO is a library for managing concurrent socketio, cv2, and pyserial processes. Useful for making robots or devices with Arduinos and Raspberry Pi. It was born in the context of remote laboratories, hence its name, where I used and developed several prototypes where the code began to redound. That's where I extracted the modules from this library. The hardware architecture that I used to employ was the following:So I programmed the following architectureFeaturesMultiple Camera APIMultiple Serial APIEvent-driven programming API for Serial.Event-driven programming API for Cameras.MJPEG streamer with SocketIOInstallationFirst you need to create a virtualenv:python3 -m venv venvThen you should active it:source venv/bin/activateAfter choose an option for install remio, for example using pip:# Pypi source
pip install remio

# Github source
pip install "git+https://github.com/Hikki12/remio"Or if you prefer, clone the repository:git clone https://github.com/Hikki12/remio

cd remio

pip install .DevelopmentIf you are a devolper, install the library as follows:pip install -e .Multiple Cameras APIimporttimeimportcv2fromremioimportCameras# Define devicesdevices={"webcam1":{"src":0,"size":[400,300],"fps":None,"reconnectDelay":5,"backgroundIsEnabled":True,"emitterIsEnabled":False,},"webcam2":{"src":"http://192.168.100.70:3000/video/mjpeg","size":[400,300],"fps":None,"reconnectDelay":5,"backgroundIsEnabled":True,"emitterIsEnabled":False,},}# Intialize Serial managercamera=Cameras(devices=devices)# Start device(s) connection on backgroundcamera.startAll()# Set a FPS speed to display image(s)FPS=20T=1/FPSwhileTrue:t0=time.time()webcam1,webcam2=camera.read(asDict=False)camera.clearAllFrames()# to avoid repeated framesifwebcam1isnotNone:cv2.imshow("webcam1",webcam1)ifwebcam2isnotNone:cv2.imshow("webcam2",webcam2)ifcv2.waitKey(1)&0xFF==ord("q"):breakt1=time.time()# Get a fixed delay value (t1 - t0) + delay = Tdelay=abs(T-(t1-t0))time.sleep(delay)# Close all Windowscv2.destroyAllWindows()# Stop all Running devicescamera.stopAll()Multiple Serial API"""Multiple serial devices management."""importtimefromremioimportSerials# Define devicesdevices={"arduino1":{"port":"/dev/cu.usbserial-1440","baudrate":9600,"emitterIsEnabled":True,# Enable on/emit callbacks"reconnectDelay":5,},"arduino2":{"port":"COM2","baudrate":9600,"emitterIsEnabled":True,"reconnectDelay":5,},}# Intialize Serial managerserial=Serials(devices=devices)# Configure callbacksserial.on("connection",lambdastatus:print(f"serial connected:{status}"))# Start device(s) connection on backgroundserial.startAll()whileTrue:print("Doing some tasks...")time.sleep(1)Simplejpeg APIREMIO usessimplejpeglibrary for encode camera images. You could used its API as follows:importtimefromremioimportCamera# Initialize camera devicecamera=Camera(src=0,fps=15,size=[800,600],flipX=True)whileTrue:jpeg=camera.jpeg()time.sleep(1/10)A simple MJPEG ServerYou could server your camera image with the MJPEG server, with a few lines:"""A simple MJPEG."""fromremioimportCamera,MJPEGServerencoderParams={"quality":90,"colorspace":"bgr","colorsubsampling":"422","fastdct":True,}# Initialize camera devicecamera=Camera(src=0,fps=15,size=[800,600],flipX=True,encoderParams=encoderParams)# Configure MJPEG Serverserver=MJPEGServer(camera=camera,ip="0.0.0.0",port=8080,endpoint="/video/mjpeg",fps=15)try:server.run(display_url=True,start_camera=True)exceptKeyboardInterrupt:server.stop(stop_camera=True)# The video must be accessible through the generated link>>MJPEGserverrunningonhttp://0.0.0.0:8080/video/mjpegExamplesYou could see more exampleshere.ResourcesChangelogCopyrightCopyright (c) hikki12 2022This library is released under theApache 2.0 License.