小弟用socket programimg传jpg档成功,
但同样程式改成png档却失败,
请问版上高手该如何修改?谢谢!!
说明:以下程式是jpg成功版本,
png失败版本是把server.py三行注解code拿来用
server.py (传图档出去)
===========================
import socket
import cv2
import numpy
frame = cv2.imread('f00000.jpg')
#frame = cv2.imread('166.png') ###############png失败版本
TCP_IP = "127.0.0.1"
TCP_PORT = 9955
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(True)
conn, addr = s.accept()
encode_param=[int(cv2.IMWRITE_JPEG_QUALITY),90]
result, imgencode = cv2.imencode('.jpg', frame, encode_param)
###############png失败版本
#encode_param=[int(cv2.IMWRITE_PNG_COMPRESSION),3]
#result, imgencode = cv2.imencode('.png', frame, encode_param)
data = numpy.array(imgencode)
stringData = data.tostring()
conn.send( str(len(stringData)).ljust(16));
conn.send( stringData );
decimg=cv2.imdecode(data,1)
cv2.imshow('SERVER2',decimg)
cv2.waitKey(3000)
stringData = '100'
conn.send(stringData);
===========================
client.py (接收图档)
===========================
import socket
import cv2
import numpy
TCP_IP = "127.0.0.1"
TCP_PORT = 9955
sock = socket.socket()
sock.connect((TCP_IP, TCP_PORT))
while 1:
newbuf = sock.recv(16)
if int(newbuf) == 100:
break
stringData = sock.recv(int(newbuf))
data = numpy.fromstring(stringData, dtype='uint8')
decimg=cv2.imdecode(data,1)
cv2.imshow('CLIENT2',decimg)
cv2.waitKey(5000)
sock.close()
cv2.destroyAllWindows()
===========================