Ask Your Question

Revision history [back]

Encoding corrupts image!

Hey!

I am using OpenCV for Face Recognition. For some reason I have to encode the face image into a string and send it to a server where the recognition part is done. However, the results are not the same as if I did the recognition directly on the taken picture.


import cv2

img = cv2.imread('/path/to/file.jpg')

recognizer.predict(img) # returns some id

#encode data
encode_param=[int(cv2.IMWRITE_JPEG_QUALITY),90]
result, imgencode = cv2.imencode('.jpg', img, encode_param)
data = numpy.array(imgencode)
stringData = data.tostring()

#decode
data = numpy.fromstring(stringData, dtype='uint8')
decimg = cv2.imdecode(data,1)

recognizer.predict(decimg) # should return the same id, but does not

What could be the problem?

Thanks a lot in advance. :) Arminius