久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Python OpenCV將圖像轉(zhuǎn)換為字節(jié)字符串?

Python OpenCV convert image to byte string?(Python OpenCV將圖像轉(zhuǎn)換為字節(jié)字符串?)
本文介紹了Python OpenCV將圖像轉(zhuǎn)換為字節(jié)字符串?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在使用 PyOpenCV.如何在沒有臨時文件和 imwrite 的情況下將 cv2 圖像(numpy)轉(zhuǎn)換為二進(jìn)制字符串以寫入 MySQL db?

I'm working with PyOpenCV. How to convert cv2 image (numpy) to binary string for writing to MySQL db without a temporary file and imwrite?

我用谷歌搜索了它,但什么也沒找到......

I googled it but found nothing...

我正在嘗試 imencode,但它不起作用.

I'm trying imencode, but it doesn't work.

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()))

錯誤:

  File "server.py", line 16, in do_GET
  self.wfile.write(cv2.imencode('png', capture.read()))
  TypeError: img is not a numerical tuple

幫助別人!

推薦答案

如果你有一個圖像 img(這是一個 numpy 數(shù)組),你可以使用以下方法將其轉(zhuǎn)換為字符串:

If you have an image img (which is a numpy array) you can convert it into string using:

>>> img_str = cv2.imencode('.jpg', img)[1].tostring()
>>> type(img_str)
 'str'

現(xiàn)在您可以輕松地將圖像存儲在數(shù)據(jù)庫中,然后使用以下方法恢復(fù)它:

Now you can easily store the image inside your database, and then recover it by using:

>>> nparr = np.fromstring(STRING_FROM_DATABASE, np.uint8)
>>> img = cv2.imdecode(nparr, cv2.CV_LOAD_IMAGE_COLOR)

您需要將 STRING_FROM_DATABASE 替換為包含對包含圖像的數(shù)據(jù)庫的查詢結(jié)果的變量.

where you need to replace STRING_FROM_DATABASE with the variable that contains the result of your query to the database containing the image.

這篇關(guān)于Python OpenCV將圖像轉(zhuǎn)換為字節(jié)字符串?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 久久精品亚洲精品国产欧美 | 福利精品 | 欧美在线a | 精品国产乱码久久久久久果冻传媒 | 国产成人精品一区二区三区网站观看 | 一级黄色录像片子 | 可以免费观看的av片 | 欧美三级电影在线播放 | 欧美日韩亚洲系列 | 性色网站 | 综合视频在线 | 精品欧美| 日韩在线一区二区三区 | 黄色网页在线观看 | 亚洲精品国产综合区久久久久久久 | 亚洲福利av | 欧洲性生活视频 | 精品国产乱码久久久久久果冻传媒 | 韩日精品一区 | 日本一区二区三区免费观看 | 91资源在线观看 | 中文字幕 国产精品 | 毛片一区二区三区 | 色爱av| 欧美精品乱码久久久久久按摩 | 久久精品成人 | 亚洲精品视频一区 | 亚洲国产精品一区二区三区 | 欧美在线一区视频 | 亚洲经典一区 | 成人av免费看 | 97视频久久| 天天色av | 日本成人福利 | 成人啊啊啊 | 国产福利二区 | 日韩精品不卡 | 天天干成人网 | 久久免费福利 | 国产一区二区久久久 | 天天爱av|