Python OpenCV convert image to byte string? -
i'm working pyopencv. how convert cv2 image (numpy) binary string writing mysql db without temporary file , imwrite
?
i'm google nothing found...
i'm trying imencode
, doesn't works
capture = cv2.videocapture(url.path) capture.set(cv2.cv.cv_cap_prop_pos_msec, float(url.query)) self.wfile.write(cv2.imencode('png', capture.read()))
error:
file "server.py", line 16, in do_get self.wfile.write(cv2.imencode('png', capture.read())) typeerror: img not numerical tuple
help somebody!
if have image img
(which numpy array) can convert string using:
>>> img_str = cv2.imencode('.jpg', img)[1].tostring() >>> type(img_str) 'str'
no can store image inside database, , recover using:
>>> nparr = np.fromstring(string_from_database, np.uint8) >>> img = cv2.imdecode(nparr, cv2.cv_load_image_color)
where need replace string_from_database
variable contains result of query database containing image.
Comments
Post a Comment