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

  • <small id='kbz0W'></small><noframes id='kbz0W'>

      <legend id='kbz0W'><style id='kbz0W'><dir id='kbz0W'><q id='kbz0W'></q></dir></style></legend>
    1. <tfoot id='kbz0W'></tfoot>
    2. <i id='kbz0W'><tr id='kbz0W'><dt id='kbz0W'><q id='kbz0W'><span id='kbz0W'><b id='kbz0W'><form id='kbz0W'><ins id='kbz0W'></ins><ul id='kbz0W'></ul><sub id='kbz0W'></sub></form><legend id='kbz0W'></legend><bdo id='kbz0W'><pre id='kbz0W'><center id='kbz0W'></center></pre></bdo></b><th id='kbz0W'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='kbz0W'><tfoot id='kbz0W'></tfoot><dl id='kbz0W'><fieldset id='kbz0W'></fieldset></dl></div>
      • <bdo id='kbz0W'></bdo><ul id='kbz0W'></ul>

        android中帶有opencv的kivy相機(jī)應(yīng)用程序顯示黑屏

        kivy camera application with opencv in android shows black screen(android中帶有opencv的kivy相機(jī)應(yīng)用程序顯示黑屏)

          <tbody id='g5PGA'></tbody>
          <tfoot id='g5PGA'></tfoot>
            <bdo id='g5PGA'></bdo><ul id='g5PGA'></ul>

            1. <legend id='g5PGA'><style id='g5PGA'><dir id='g5PGA'><q id='g5PGA'></q></dir></style></legend>
              1. <small id='g5PGA'></small><noframes id='g5PGA'>

                • <i id='g5PGA'><tr id='g5PGA'><dt id='g5PGA'><q id='g5PGA'><span id='g5PGA'><b id='g5PGA'><form id='g5PGA'><ins id='g5PGA'></ins><ul id='g5PGA'></ul><sub id='g5PGA'></sub></form><legend id='g5PGA'></legend><bdo id='g5PGA'><pre id='g5PGA'><center id='g5PGA'></center></pre></bdo></b><th id='g5PGA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='g5PGA'><tfoot id='g5PGA'></tfoot><dl id='g5PGA'><fieldset id='g5PGA'></fieldset></dl></div>
                  本文介紹了android中帶有opencv的kivy相機(jī)應(yīng)用程序顯示黑屏的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我正在嘗試在 Kivy 中構(gòu)建基于 OpenCv 的相機(jī) Android 應(yīng)用:

                  I'm trying to build an camera Android app based on OpenCv in Kivy:

                  ma??in.py

                  import kivy
                  from kivy.app import App
                  from kivy.uix.label import Label
                  from kivy.uix.camera import Camera
                  import cv2
                  from kivy.uix.image import Image
                  from kivy.clock import Clock
                  from kivy.graphics.texture import Texture
                  import numpy as np
                  
                  class KivyCamera(Image):
                      def __init__(self, capture, fps, **kwargs):
                          super(KivyCamera, self).__init__(**kwargs)
                          self.capture = capture
                          Clock.schedule_interval(self.update, 1.0 / fps)
                  
                      def update(self, dt):
                          ret, frame = self.capture.read()
                  
                          if ret:
                              # convert it to texture
                              buf1 = cv2.flip(frame, 0)
                              buf = buf1.tostring()
                              image_texture = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
                              image_texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
                              # display image from the texture
                              self.texture = image_texture
                  
                  class MainApp(App):
                      def build(self):
                          self.capture = cv2.VideoCapture(0)
                          self.camera = KivyCamera(capture=self.capture, fps=30)
                          return self.camera
                  
                  if __name__== "__main__":
                      MainApp().run()
                  

                  buildozer.spec

                  [app]
                  title = Test_app
                  package.name = myapp
                  package.domain = org.test
                  source.dir = .
                  source.include_exts = py,png,jpg,kv,atlas,xml
                  version = 0.1
                  requirements = python3,kivy,numpy,opencv
                  orientation = portrait
                  
                  # Android specific
                  fullscreen = 0
                  android.permissions = INTERNET, ACCESS_FINE_LOCATION, WRITE_EXTERNAL_STORAGE, CAMERA
                  android.arch = armeabi-v7a
                  [buildozer]
                  log_level = 2
                  warn_on_root = 1
                  

                  代碼在 Windows 中成功運(yùn)行.然后我用 buildozer for android 構(gòu)建了代碼,當(dāng)我打開 Android 應(yīng)用程序時(shí),它顯示一個(gè)黑屏,屏幕左角有一個(gè)小方塊.我認(rèn)為 cv2.VideoCapture() 工作不正常.所以我將 cv2.VideoCapture(0) 更改為 cv2.VideoCapture(-1) 和 cv2.VideoCapture(1).但兩者都不起作用.

                  Code works successfully in windows. Then i have build the the code with buildozer for android, when I open the Android App it shows a black screen with a small square in the left corner of the screen. I think the cv2.VideoCapture() is not working properly.So I change cv2.VideoCapture(0) to cv2.VideoCapture(-1) and to cv2.VideoCapture(1). But both doesn't work.

                  誰(shuí)能幫我解決這個(gè)問(wèn)題?

                  Can anyone help me out with this ?

                  推薦答案

                  我有 2 個(gè)解決方案可以讓它在 Android 上運(yùn)行.

                  I have 2 solutions to get it to work on Android.

                  解決方案 1:

                  我的靈感來(lái)自 GitHub 上的 kivy-for-android-opencv-demo:鏈接!因?yàn)?Kivy 不再支持 Python2,所以這里是我針對(duì) Python3 的解決方案.

                  I was inspired by kivy-for-android-opencv-demo, found on GitHub: link! Because Kivy no longer supports Python2, here is my solution for Python3.

                  main.py

                  from kivy.app import App
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.graphics.texture import Texture
                  from kivy.uix.camera import Camera
                  from kivy.lang import Builder
                  import numpy as np
                  import cv2
                  
                  Builder.load_file("myapplayout.kv")
                  
                  class AndroidCamera(Camera):
                      camera_resolution = (640, 480)
                      counter = 0
                  
                      def _camera_loaded(self, *largs):
                          self.texture = Texture.create(size=np.flip(self.camera_resolution), colorfmt='rgb')
                          self.texture_size = list(self.texture.size)
                  
                      def on_tex(self, *l):
                          if self._camera._buffer is None:
                              return None
                          frame = self.frame_from_buf()
                          self.frame_to_screen(frame)
                          super(AndroidCamera, self).on_tex(*l)
                  
                      def frame_from_buf(self):
                          w, h = self.resolution
                          frame = np.frombuffer(self._camera._buffer.tostring(), 'uint8').reshape((h + h // 2, w))
                          frame_bgr = cv2.cvtColor(frame, 93)
                          return np.rot90(frame_bgr, 3)
                  
                      def frame_to_screen(self, frame):
                          frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                          cv2.putText(frame_rgb, str(self.counter), (20, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv2.LINE_AA)
                          self.counter += 1
                          flipped = np.flip(frame_rgb, 0)
                          buf = flipped.tostring()
                          self.texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')
                  
                  class MyLayout(BoxLayout):
                      pass
                  
                  class MyApp(App):
                      def build(self):
                          return MyLayout()
                  
                  if __name__ == '__main__':
                      MyApp().run()
                  

                  myappayout.kv

                  myapplayout.kv

                  <MyLayout>
                      orientation: 'vertical'
                      size: root.width, root.height
                  
                      AndroidCamera:
                          index: 0
                          resolution: self.camera_resolution
                          allow_stretch: True
                          play: True
                  

                  在 buildozer.spec 中:

                  in buildozer.spec:

                  requirements = python3,kivy==2.0.0,opencv==4.5.2,numpy
                  android.permissions = CAMERA
                  


                  解決方案 2:


                  Solution 2:

                  我從顯示的相機(jī)圖像的小部件中獲取幀,每秒 4 次.如果您不需要每一個(gè)框架,并且不需要在框架頂部繪制文本或框等內(nèi)容,那么這是一個(gè)簡(jiǎn)單的解決方案.

                  I get the frame from the widget of the displayed camera image, 4 times a second. If you don't need every single frame, and it's not necessary to draw things like text or boxes on top of the frames, then it's an easy solution.

                  main.py

                  from kivy.app import App
                  from kivy.uix.camera import Camera
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.lang import Builder
                  from kivy.clock import Clock
                  import numpy as np
                  import cv2
                  
                  Builder.load_file('myapplayout.kv')
                  
                  class AndroidCamera(Camera):
                      camera_resolution = (640, 480)
                      cam_ratio = camera_resolution[0] / camera_resolution[1]
                  
                  class MyLayout(BoxLayout):
                      pass
                  
                  
                  class MyApp(App):
                      counter = 0
                  
                      def build(self):
                          return MyLayout()
                  
                      def on_start(self):
                          Clock.schedule_once(self.get_frame, 5)
                  
                      def get_frame(self, dt):
                          cam = self.root.ids.a_cam
                          image_object = cam.export_as_image(scale=round((400 / int(cam.height)), 2))
                          w, h = image_object._texture.size
                          frame = np.frombuffer(image_object._texture.pixels, 'uint8').reshape(h, w, 4)
                          gray = cv2.cvtColor(frame, cv2.COLOR_RGBA2GRAY)
                          self.root.ids.frame_counter.text = f'frame: {self.counter}'
                          self.counter += 1
                          Clock.schedule_once(self.get_frame, 0.25)
                  
                  if __name__ == "__main__":
                      MyApp().run()
                  

                  myappayout.kv

                  myapplayout.kv

                  <MyLayout>:
                      orientation: 'vertical'
                      size: root.width, root.height
                  
                      GridLayout:
                          rows: 2
                  
                          RelativeLayout:
                              size_hint: 1, 0.8
                  
                              AndroidCamera:
                                  index: 0
                                  id: a_cam
                                  resolution: self.camera_resolution
                                  allow_stretch: True
                                  play: True
                                  canvas.before:
                                      PushMatrix
                                      Rotate:
                                          angle: -90
                                          origin: self.center
                                      Scale:
                                          x: self.cam_ratio
                                          y: self.cam_ratio
                                          origin: self.center
                                  canvas.after:
                                      PopMatrix
                  
                          Label:
                              size_hint: 1, 0.2
                              id: frame_counter
                              font_size: self.height * 0.4
                              text: ''
                  

                  buildozer.spec 與解決方案 1 中的相同.

                  The buildozer.spec is the same as in solution 1.

                  最后,安裝后別忘了給相機(jī)添加權(quán)限.(我的代碼中沒(méi)有包含權(quán)限請(qǐng)求.)

                  Finally, don't forget to add permission to camera after installation. (No permission request is included in my code.)

                  這篇關(guān)于android中帶有opencv的kivy相機(jī)應(yīng)用程序顯示黑屏的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當(dāng)前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測(cè)位置提供者?GPS 或網(wǎng)絡(luò)提供商)
                  Get current location during app launch(在應(yīng)用啟動(dòng)期間獲取當(dāng)前位置)
                  locationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)
                  • <small id='zNFDU'></small><noframes id='zNFDU'>

                        <bdo id='zNFDU'></bdo><ul id='zNFDU'></ul>

                      • <tfoot id='zNFDU'></tfoot>
                        <legend id='zNFDU'><style id='zNFDU'><dir id='zNFDU'><q id='zNFDU'></q></dir></style></legend>

                            <tbody id='zNFDU'></tbody>
                          <i id='zNFDU'><tr id='zNFDU'><dt id='zNFDU'><q id='zNFDU'><span id='zNFDU'><b id='zNFDU'><form id='zNFDU'><ins id='zNFDU'></ins><ul id='zNFDU'></ul><sub id='zNFDU'></sub></form><legend id='zNFDU'></legend><bdo id='zNFDU'><pre id='zNFDU'><center id='zNFDU'></center></pre></bdo></b><th id='zNFDU'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zNFDU'><tfoot id='zNFDU'></tfoot><dl id='zNFDU'><fieldset id='zNFDU'></fieldset></dl></div>

                          1. 主站蜘蛛池模板: 午夜在线电影网 | 国产一区二区三区久久 | 欧洲成人| 国产区在线免费观看 | 在线免费国产视频 | 中文字幕日韩欧美一区二区三区 | 国产精品久久久久久久久久久久冷 | 亚洲h视频| 桃色五月| 国产精品久久久一区二区三区 | 中文字幕伊人 | 国产精品一区二区在线 | 69av网| 91久久久久久久久久久久久 | 久操福利 | 国产乱码精品一区二区三区忘忧草 | 亚洲免费一区二区 | 最近中文字幕第一页 | 国产精品久久久亚洲 | 欧美一区二区三区四区视频 | 丁香久久| 国产无人区一区二区三区 | 久久国产精品色av免费观看 | 亚洲不卡在线观看 | 久久一区视频 | 草草影院ccyy | 亚洲视频网 | 国产亚洲欧美日韩精品一区二区三区 | 久久精品国产一区二区电影 | 羞视频在线观看 | 夜夜艹天天干 | 99综合在线 | 亚洲精品国产第一综合99久久 | 日韩欧美视频免费在线观看 | 欧美一级黄带 | a免费视频 | 成人午夜毛片 | 中文区中文字幕免费看 | 精品国产欧美日韩不卡在线观看 | 久久aⅴ乱码一区二区三区 91综合网 | 久久精品91久久久久久再现 |