我一直在尝试制作一个打开设备相机的应用,但是我收到了这个错误:
[CRITICAL ] [Camera ] Unable to find any valuable Camera provider at all!
videocapture - ImportError: No module named VideoCapture
File "C:\Users\Gaston\Downloads\Kivy-1.9.0-py2.7-win32-x86\kivy27\kivy\core\__init__.py", line 57, in core_select_lib
fromlist=[modulename], level=0)
File "C:\Users\Gaston\Downloads\Kivy-1.9.0-py2.7-win32-x86\kivy27\kivy\core\camera\camera_videocapture.py", line 15, in <module>
from VideoCapture import Device
opencv - ImportError: No module named cv
File "C:\Users\Gaston\Downloads\Kivy-1.9.0-py2.7-win32-x86\kivy27\kivy\core\__init__.py", line 57, in core_select_lib
fromlist=[modulename], level=0)
File "C:\Users\Gaston\Downloads\Kivy-1.9.0-py2.7-win32-x86\kivy27\kivy\core\camera\camera_opencv.py", line 20, in <module>
import cv
尝试安装opencv但仍然无法正常工作。我的代码只是kivy文档中的代码示例: http://kivy.org/docs/examples/gen__camera__main__py.html
答案 0 :(得分:0)
对不起,我没有足够的声誉来评论,但我相信你应该检查一下你是否有任何可以支持Camera的库。我相信你正在导入cv而不是cv2。如果问题仍然存在,请检查是否在文件位置中安装了必需的库。我从网上得到了这个代码。它在我的电脑上运行可能会帮助你: -
from kivy.app import App
from kivy.uix.image import Image
from kivy.clock import Clock
from kivy.graphics.texture import Texture
import cv2
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.uix.button import Button
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 CamApp(App):
def build(self):
self.capture = cv2.VideoCapture(1)
self.my_camera = KivyCamera(capture=self.capture, fps=10,resolution=(1280,960))
return self.my_camera
def on_stop(self):
#without this, app will not exit even if the window is closed
self.capture.release()
if __name__ == '__main__':
CamApp().run()