English 中文(简体)
外部网络不为开放式和开放式飞机工作
原标题:External Webcam not working for Opencv and Python

Im利用Adhurcv2模块操作节目。

我能够访问封建的网络运动,但当我利用外部网络作风时,它就没有工作。

我使用了所有法典。

VideoCapture(1) # or any other no.s like 0,1,2,3 etc etc.

我甚至还利用装置经理使内在设计的网络广告失效。

但无所作为。 I m 使用 p。 我也迅速进行了指挥。 它依然没有工作。

我发现以下错误:

runfile( C:/Users/Prashant/Documents/Python Scripts/Circledetection.py ,     wdir=r C:/Users/Prashant/Documents/Python Scripts )
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ......modulesimgprocsrccolor.cpp, line 3402
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:Python27libsite-packagesspyderlibwidgetsexternalshellsitecustomize.py", line 540, in runfile
    execfile(filename, namespace)
  File "C:/Users/Prashant/Documents/Python Scripts/Circledetection.py", line 27, in <module>
    prev_gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
cv2.error: ......modulesimgprocsrccolor.cpp:3402: error: (-215) scn == 3 || scn == 4
问题回答

That assertion means that your image does not have 3 (RGB, BGR, etc) channels, or 4 channels (3 channels + alpha). This can be caused, obviously, by the image not existing at all.

虽然这可能是因为你的照相机是徒劳的,但同样可能的是,你的照相机不会给头几读(......)的可用框架,因为它仍在准备之中。

The easiest way to solve this, assuming you use something like retv, frame = cam.read() is to check if frame: or if retv:.

如果没有图像,它是否绕过你的处理,在几个框架内,你应该有可读的投入。

You mentioned VideoCapture(0) to VideoCapture(1).
"1" means external camera number.

import cv2
import numpy as np

cap = cv2.VideoCapture(1) 
while(1):
    ret, frame = cap.read()
    #print(height)
    #cv2.imshow("Cropped Image", crop_img)
    #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow( frame ,frame)
    if cv2.waitKey(1) & 0xFF == ord( q ):
        break

cap.release()
cv2.destroyAllWindows()

你们是否保证使用正确的指数? 用户也可使用<代码>Videocapture>,因为外部广告有时是输入清单的最后内容。 也可以归还装置名称,因此,你可以试图查阅输入装置指数清单,并打印其“友好名称”,以确保你使用正确的名称。

OpenCV requires the following dependencies to work with the USB cameras. Install the dependencies from the following commands:

  • 校准视频投入/产出开发图书馆

    sudo apt-get install libavformat-dev libavutil-dev libswscale-dev
    
  • Video4Linux camera development libraries

    sudo apt-get install libv4l-dev
    
  • OpenGL development libraries (to allow creating graphical windows)

    sudo apt-get install libglew-dev
    
  • GTK development libraries (to allow creating graphical windows)

    sudo apt-get install libgtk2.0-dev
    

它为我工作。

开放式电脑要求以下附属公司与USB照相机合作。 全部来自以下指挥单位:

校准视频投入/产出开发图书馆

sudo apt-get install libavformat-dev libavutil-dev libswscale-dev Video4Linux camera development libraries

sudo apt-get install libv4l-dev OpenGL development libraries (to allow creating graphical windows)

sudo apt-get install libglew-dev GTK development libraries (to allow creating graphical windows)

sudo aptgetstalgtk2.0-dev

您可以尝试安装虚拟环境:

pip install virtualenv

然后:

python -m virtualenv .

接着实施你 p的节目:

cv2.VideoCapture(0)




相关问题
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 ]="...

热门标签