2013-02-20 37 views
0

我想用Web界面(用CherryPy製作)顯示OpenCV處理後的圖像。下面的代碼工作正常,但有沒有辦法執行這樣的任務沒有寫/讀圖像文件?顯示numpy代表web界面中的birmap [Python]

import cherrypy 
import cv2 


class Picture(object): 
    def __init__(self): 
     self.cam = cv2.VideoCapture(0) 

    @cherrypy.expose 
    def index(self): 
     _, image = self.cam.read() 
     cv2.imwrite('temp.jpg', image) 
     with open('temp.jpg', 'rb') as temp_file: 
      data = temp_file.read() 

     cherrypy.response.headers['Content-Type'] = 'image/jpeg' 
     return data 


if __name__ == '__main__': 
    cherrypy.quickstart(Picture()) 

回答

1

可以cv2.imencode()在內存中的圖像,而不是保存/在

+0

感謝讀書回來了!不明白我在閱讀文檔時錯過了什麼。 – Igonato 2013-02-20 10:43:36