Reputation: 271
So I am using a camera module which only has python>3.7 support. I am trying to use that data to do some machine learning. Unfortunately, the machine learning module only has python<3.7 support. I was thinking I could launch a script to grab the video images using python3.8 and then catch the images using a websocket or zmq in python 3.6. Is there a faster way to do this?
Solved following advice in the replies:
python3.8 video.py | python3.6 ml.py
video.py:
import sys
import numpy as np
import cv2
from PIL import Image
import io
img = cv2.imread('cat.jpeg')
bimg = cv2.imencode('.jpeg',img)[1]
sys.stdout.buffer.write(bimg)
ml.py:
import sys
from PIL import Image
import io
import cv2
import numpy as np
from io import BytesIO
data = sys.stdin.buffer.read()
img_np = cv2.imdecode(np.frombuffer(BytesIO(data).read(), np.uint8), cv2.IMREAD_UNCHANGED)
cv2.imshow('image', img_np)
cv2.waitKey(0)
Upvotes: 1
Views: 298
Reputation: 87134
Using standard OS functionality, pipe the output from the video capture script to the ML script:
$ python3.8 video.py | python3.6 ml.py
You would need to write bytes to stdout in video.py and read bytes from stdin in ml.py.
Upvotes: 3