Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv 将iplimage转换为PhotoImage以在tkinter画布上绘制_Opencv_Tkinter_Iplimage - Fatal编程技术网

Opencv 将iplimage转换为PhotoImage以在tkinter画布上绘制

Opencv 将iplimage转换为PhotoImage以在tkinter画布上绘制,opencv,tkinter,iplimage,Opencv,Tkinter,Iplimage,下面是一些代码: if self.detect == True: haars = self.loadHaars() image = self.detectRedEyes(self.cam, haars[0], haars[1]) # -><type 'cv2.cv.iplimage'> self.image = self.canvas.create_image(0,0,image=ImageTk.PhotoImage(

下面是一些代码:

      if self.detect == True:
        haars = self.loadHaars()
        image = self.detectRedEyes(self.cam, haars[0], haars[1]) # -><type 'cv2.cv.iplimage'>
        self.image = self.canvas.create_image(0,0,image=ImageTk.PhotoImage(image),anchor=tk.NW)
      else:
其中img是videocapture.read()的输出 有什么问题?有人能告诉我怎么了吗? 我用misha的代码解决了这个问题:

        #convert iplimage to PhotoImage via PIL image
        pil_image = Image.fromstring(
                'RGB',
                cv.GetSize(image),
                image.tostring(),
                'raw',
                'BGR',
                image.width*3,
                0)
        tk_image = ImageTk.PhotoImage(pil_image)
但问题是相当实际的——为什么它不起作用,如果可能的话,做得比米莎好

#convert numpy.ndarray to iplimage
ipl_img = cv2.cv.CreateImageHeader((img.shape[1], img.shape[0]), cv.IPL_DEPTH_8U, 3)
cv2.cv.SetData(ipl_img, img.tostring(),img.dtype.itemsize * 3 * img.shape[1])
        #convert iplimage to PhotoImage via PIL image
        pil_image = Image.fromstring(
                'RGB',
                cv.GetSize(image),
                image.tostring(),
                'raw',
                'BGR',
                image.width*3,
                0)
        tk_image = ImageTk.PhotoImage(pil_image)