我一直在尝试制作一个可以打开设备相机的应用程序,但出现以下错误:
[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
最佳答案
很抱歉,我没有足够的声誉发表评论,但我相信你应该检查你是否有任何图书馆可以支持相机我相信你是在进口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()
关于python - OpenCV的Python/Kivy相机小部件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30294385/