English 中文(简体)
露天错误可以通过视频捕获来打开摄像机。
原标题:OpenCv error can t open camera through video capture

我在开车后,在我重新开车后,突然使用我的cam。

[ WARN:0] global /io/opencv/modules/videoio/src/cap_v4l.cpp (802) open VIDEOIO ERROR: V4L: can t open camera by index 0
Traceback (most recent call last):
  File "test.py", line 20, in <module>
    retval, buffer_img = cv2.imencode( .jpg , frame)
cv2.error: OpenCV(4.1.2) /io/opencv/modules/imgcodecs/src/loadsave.cpp:877: error: (-215:Assertion failed) !image.empty() in function  imencode 
cap = cv2.VideoCapture(0)  # here it throws an error


import json
while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    retval, buffer_img = cv2.imencode( .jpg , frame)

    resdata = base64.b64encode(buffer_img)

    resdata = "data:image/png;base64,"+ str(resdata.decode("utf-8"))
    PARAMS = { image : resdata}

    # Our operations on the frame come here
    #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow( frame ,frame)
    if cv2.waitKey(1) & 0xFF == ord( q ):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

我也尝试了cap = cv2.VideoCapture(1),但显示可以发现照相机。

我如何解决这一问题?

问题回答

我有同样的错误。 图1

cap = cv2.VideoCapture(-1)

这个问题已经解决。

当我创立了2.VideoCapture(0)不止一个例子时,我就谈同样的问题。 因此,如果贵国的法典含有多处初始化或多处称呼V2.VideoCapture(0)的章节,就会检查。 我面临这一问题,同时以减速方式操作激光器服务器,因为它称电压器是2倍。

import cv2
cap = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture(0)
while True:

    ret, frame = cap.read()
    cv2.imshow( frame ,frame)
    if cv2.waitKey(1) & 0xFF == ord( q ):
        break

cap.release()
cv2.destroyAllWindows()

Error:

python3 debugCamera.py 
[ WARN:0] global /io/opencv/modules/videoio/src/cap_v4l.cpp (887) open VIDEOIO(V4L2:/dev/video0): can t open camera by index

Most likely a permission issue on /dev/video0.

Check if you are part of "video" group.
id -a

if you don t see video in your group list add sudo usermod -a -G video

for Ubuntu users:(20.04)
sudo usermod -a -G video $LOGNAME

记录和记录。

I had the same problem, Just change 0 to 1,then to -1 and back again to 0. Don t know why this worked for me.

我也遇到了同样的问题,并尝试了几种方法,例如:cv2.VideoCapture(-1)cv2.VideoCapture(1),但没有取得多大成功。

我在读了后继承了该条

在https://github.com/opencv/ opencv/issues/19527“rel=”https://github.com/ opencv/issues/19527上,我找到了解决办法。 录像带在功能中而不是外面。 这为我工作(乌图)

def frame_generation():

camera = cv2.VideoCapture(0) #resolved, correct position

while(True):

我将不谈这一部分。 你试图做些什么,这里只是一部能够打开你每次照相机的法典,

python: 3.7.3

OpenCV: 4.1.0

import cv2
cap = cv2.VideoCapture(0)
while True:

    ret, frame = cap.read()
    cv2.imshow( frame ,frame)
    if cv2.waitKey(1) & 0xFF == ord( q ):
        break

cap.release()
cv2.destroyAllWindows()

我也存在同样的问题。 只是将其改为1,而且它正在完全运作。 我猜测它与你使用的照相器数量有关。

例如,我猜测我有Iruin外部摄像机,这是我第一次选择,我当时没有把这个选择连接起来。

这里是错误和改正的代码。

global /tmp/pip-req-build-f51eratu/opencv/modules/videoio/src/cap_v4l.cpp (890) open VIDEOIO(V4L2:/dev/video0): can t open camera by index

Code to change:

vid = cv2.VideoCapture(1)

看来,《任择议定书》正在使用一种Raspberry PI。 Raspberry正在转向新的系统,以管理照相机,因此,当用户通过<条码>向OS升级时,照相系统会得到新的图书馆,而遗留的照相系统是残疾的。 为了让遗留的照相系统再次发挥作用,尝试

sudo raspi-config

然后选择

3 Interface Options    Configure connections to peripherals

然后选择

I1 Legacy Camera Enable/disable legacy camera support

并遵循各项指示,以便能够并继而更换。

当然,由于遗产制度被扭曲,这一摊位只能长时间工作。

就我而言,我只是把游乐重新连接到我们的港口,然后解决! 我认为,造成这一错误的原因是以错误的方式关闭窗口。 请检查在关闭窗户后是否对终点站权有任何例外。

我在乌班图也存在这个问题。

我通过这些 com子解决这一问题。

sudo adduser username video sudo usermod -a -G video username

用户名称——是贵装置的名称

页: 1

a)

(a) 从(b)到(b)到(b)项的复制指数

页: 1

只字不提:

摄像机 = cv2.VideoCapture(1000)

每一只 an子,但只改变照相机,从-1升至1,然后回到零。

video = cv2.VideoCapture(0,cv2.CAP_DSHOW)

这为我工作。

就六氯环己烷而言,确保利用V4L(为lin子提供录像)建造开放式六氯环己烷。

我每次在重新启用或更换摄像机和插头之后都这样做。

chmod 777 /dev/video0

Don t know if this is still an issue. In my case, I was getting the same error until I unplugged and plugged the usb camera. Even if I reboot, the error happened.

It s similar to someone said: my camera was already been captured. The problem is that it was not used by my script, so it was hard to identify.

A few days before the issue, I installed the motion library, but just to test something and I didn t use it anymore. The motion starts at boot, so the camera was being captured by the service. That s why only the unplug-plug worked.

我对图书馆无动于衷,错误已经发生。

正如其他捐助者指出的,对我来说,解决办法只是把照相机从USB港口拆开,然后把照照相机推回,而Raspberry PI 乌本巴的OS正在运行。

这个问题是由于中断。 例如,用关键的q来结束处决,不会突然关闭窗户。

我再次打开终点站,再次执行同样的文字,从而解决了同一问题。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...