我想在colab中使用imshow(),但是它不起作用

时间:2020-03-18 06:45:11

标签: python opencv google-colaboratory cv2 imshow

基于我尝试过的上一个线程

from google.colab.patches import cv2_imshow()

但是当我运行它时,出现以下错误:

File "<ipython-input-10-7cdf619df240>", line 1
    from google.colab.patches import cv2_imshow()
                                               ^
SyntaxError: invalid syntax

2 个答案:

答案 0 :(得分:2)

导入时不要使用()

使用

from google.colab.patches import cv2_imshow

答案 1 :(得分:0)

您也可以在colab中使用from kivy.app import App from kivy.graphics import Line from kivy.uix.scatter import Scatter from kivy.uix.relativelayout import RelativeLayout from kivy.uix.stencilview import StencilView class MyPaintWidget(Scatter): def __init__(self, **kwargs) : self.selected = None self.touched = False super(MyPaintWidget, self).__init__(**kwargs) def create_figure(self, **kwargs): (ix,iy) = self.to_local(*self.pos) (fx,fy) = self.to_local(self.pos[0] + self.size[0], self.pos[1] + self.size[1]) print ("ix " + str(ix) + " iy " + str(iy) + " fx " + str(fx) + " fy " + str(fy)) self.canvas.add(Line( points=[ix, iy, fx, fy], width=1)) return self def on_touch_down(self, touch): if self.collide_point(touch.x, touch.y): #This print I get for RelativeLayout #But for StencilView it does not work when I touch the line print("Hi you touched the line") class MyPaintApp(App): def build(self): #If parent is StencilView unable to click #but if parent is RelativeLayout, I am able to get collide_point #parent = StencilView() parent = RelativeLayout() #parent = Scatter() ix = 100. iy = 100. fx = 200. fy = 100. pos = (min(ix, fx), min(iy, fy)) size = (abs(fx-ix), abs(fy-iy)) self.painter = MyPaintWidget(pos=pos, size=size) parent.add_widget(self.painter.create_figure()) return parent if __name__ == '__main__': MyPaintApp().run() 。因此,请按照我的步骤操作...

  1. 从左侧单击文件。然后只需单击“安装驱动器”选项。需要一些时间。
  2. 然后,您可以轻松地正常使用imshow()函数。

您已使用以下格式的文件位置= >>>

imshow

然后使用以下代码= >>

!ls "/content/drive/My Drive/....."  # To go to the file location
!cp -r "/content/drive/My Drive/....."  # to copy a file to Colab