-
-
Save ilomon10/ad86ac4ccd6fcb2925a57593438a366b to your computer and use it in GitHub Desktop.
import cv2 | |
import socketio #python-socketio by @miguelgrinberg | |
import base64 | |
sio = socketio.Client() | |
sio.connect('http://x.x.x.x:xxxx) | |
cam = cv2.VideoCapture(0) | |
while (True): | |
ret, frame = cam.read() # get frame from webcam | |
res, frame = cv2.imencode('.jpg', frame) # from image to binary buffer | |
data = base64.b64encode(frame) # convert to base64 format | |
sio.emit('data', data) # send to server | |
cam.release() | |
var app = require('express')(); | |
var http = require('http').createServer(app); | |
var io = require('socket.io')(http); | |
var sizeof = require('object-sizeof'); | |
app.get('/', function (req, res) { | |
res.send('running'); | |
}) | |
io.on('connection', function (socket) { | |
socket.on('data', function (data) { // listen on client emit 'data' | |
var ret = Object.assign({}, data, { | |
frame: Buffer.from(data.frame, 'base64').toString() // from buffer to base64 string | |
}) | |
io.emit('data', ret); // emmit to socket | |
}) | |
}) | |
http.listen(3000, function () { | |
console.log('listening on *:3333'); | |
}) |
How do you do the same in reverse? (send an image from node to py)
just emit frame to python through socket and parse buffer frame.
I'm working on a project and I need to send image by node js to python function and this function return 1 or 0
plz can you help me !!
I'm working on a project and I need to send image by node js to python function and this function return 1 or 0
plz can you help me !!
@alabach if you need image on python you just emit image frame to python through socket and parse that buffer to frame, if you just need condition "is image was there" you dont need to send image to target, you just emit/send boolean to target.
The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefine
I am receiving this error
Read some documentation please
python-socketio https://python-socketio.readthedocs.io/en/latest/
socket.io https://socket.io/docs/v4
Getting started with socket.io project
node as server https://www.scaleway.com/en/docs/how-to-install-and-configure-socket-io/
python as server https://python-socketio.readthedocs.io/en/latest/server.html
Basic of socket.io
https://dev.to/uf4no/understanding-the-basics-of-socket-io-3a0e
Thanks! This is the only way I could send an image to the client through sockets.
How do you do the same in reverse? (send an image from node to py)