1

I am using raspberry pi 3 model B and Rpi camera B.(OS is raspbian stretch) I want to send an image taken by raspberry pi to my laptop (ubuntu 16.04) via TCP.Raspberry pi and laptop are connected with wifi from router. But when I receive data, process it and save it.Then the result is not correct.

Here is my client.py

from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import socket

TCP_IP = '192.168.0.109'
TCP_PORT = 5000
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (1280,720)
rawCapture = PiRGBArray(camera)

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((TCP_IP,TCP_PORT))
print('Connected to server')
# grab an image from the camera
camera.capture(rawCapture, format="bgr")
image = rawCapture.array
encoded = cv2.imencode('.jpg',image)[1]


s.sendall(encoded)
print('Done')
s.close()

Here is my server.py

import socket
import struct
import cv2
import numpy as np
TCP_IP = '0.0.0.0'
TCP_PORT = 5000
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((TCP_IP,TCP_PORT))
s.listen(1)

con = s.accept()[0]
print('Connected to client....')
count = 0

name = str(count)+'.jpg'
data = con.recv(4096)

encoded_array = np.fromstring(data,np.uint8)
decoded_image = cv2.imdecode(encoded_array,cv2.IMREAD_COLOR)
cv2.imwrite(name,decoded_image)
s.close()
con.close()

Here is my result image

Note: Raspberry pi versions --> opencv 3.4.0 ,python 3.5.3
laptop versions --> opencv 3.1.0, python 3.5.2

0 Answers0