opencv / opencv-python

Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.
https://pypi.org/project/opencv-python/
MIT License
4.47k stars 842 forks source link

TypeError: VideoCapture() takes no arguments #518

Open savadkv01 opened 3 years ago

savadkv01 commented 3 years ago

This is the code which iam tryng in PyCharm

import cv2
import time

cap = cv2.VideoCapture(0)

while True:
    success, img = cap.read()
    cv2.imshow("Image", img)
    cv2.waitKey(1)

Iam getting below error

"C:\Users\Support ACTA\AppData\Local\Programs\Python\Python37\python.exe" "E:/Project/Python/advanced computer vision/Face Detection/FaceDetectionMin.py"
Traceback (most recent call last):
  File "E:/Project/Python/advanced computer vision/Face Detection/FaceDetectionMin.py", line 4, in <module>
    cap = cv2.VideoCapture(0)
TypeError: VideoCapture() takes no arguments

If I use the the video path also, same error iam getting

asmorkalov commented 3 years ago

Please provide cv2.getBuildInformation() call output.

savadkv01 commented 3 years ago
>>> import cv2
>>> cv2.getBuildInformation()
'
General configuration for OpenCV 4.5.3 =====================================
  Version control:               4.5.3

  Extra modules:
    Location (extra):            C:/Users/runneradmin/AppData/Local/Temp/pip-req-build-_xlv4eex/opencv_contrib/modules
    Version control (extra):     4.5.3

  Platform:
    Timestamp:                   2021-07-09T11:26:41Z
    Host:                        Windows 10.0.17763 AMD64
    CMake:                       3.20.5
    CMake generator:             Visual Studio 14 2015 Win64
    CMake build tool:            MSBuild.exe
    MSVC:                        1900
    Configuration:               Debug Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (15 files):         + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (29 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2

  C/C++:
    Built as dynamic libs?:      NO
    C++ standard:                11
    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe  (ver 19.0.24245.0)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MT /O2 /Ob2 /DNDEBUG 
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MTd /Zi /Ob0 /Od /RTC1 
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP   /MT /O2 /Ob2 /DNDEBUG 
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP /MTd /Zi /Ob0 /Od /RTC1 
    Linker flags (Release):      /machine:x64  /NODEFAULTLIB:atlthunk.lib /INCREMENTAL:NO  /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib
    Linker flags (Debug):        /machine:x64  /NODEFAULTLIB:atlthunk.lib /debug /INCREMENTAL  /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          wsock32 comctl32 gdi32 ole32 setupapi ws2_32
    3rdparty dependencies:       libprotobuf ade ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf zlib quirc ippiw ippicv

  OpenCV modules:
    To be built:                 aruco barcode bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    freetype world
    Disabled by dependency:      -
    Unavailable:                 alphamat cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv hdf java julia matlab ovis python2 sfm ts viz
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO

  Windows RT support:            NO

  GUI: 
    Win32 UI:                    YES
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.11)
    JPEG:                        build-libjpeg-turbo (ver 2.1.0-62)
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.2.0)
    JPEG 2000:                   build (ver 2.4.0)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (58.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      avresample:                YES (4.0.0)
    GStreamer:                   NO
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      YES

  Parallel framework:            Concurrency

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2020.0.0 Gold [2020.0.0]
           at:                   C:/Users/runneradmin/AppData/Local/Temp/pip-req-build-_xlv4eex/_skbuild/win-amd64-3.7/cmake-build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                C:/Users/runneradmin/AppData/Local/Temp/pip-req-build-_xlv4eex/_skbuild/win-amd64-3.7/cmake-build/3rdparty/ippicv/ippicv_win/iw
    Lapack:                      NO
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  OpenCL:                        YES (NVD3D11)
    Include path:                C:/Users/runneradmin/AppData/Local/Temp/pip-req-build-_xlv4eex/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 3:
    Interpreter:                 C:/hostedtoolcache/windows/Python/3.7.9/x64/python.exe (ver 3.7.9)
    Libraries:                   C:/hostedtoolcache/windows/Python/3.7.9/x64/libs/python37.lib (ver 3.7.9)
    numpy:                       C:/Users/RUNNER~1/AppData/Local/Temp/pip-build-env-fgp09wnn/overlay/Lib/site-packages/numpy/core/include (ver 1.14.5)
    install path:                python

  Python (for build):            C:/hostedtoolcache/windows/Python/2.7.18/x64/python.exe

  Java:                          
    ant:                         NO
    JNI:                         C:/hostedtoolcache/windows/Java_Adopt_jdk/8.0.292-10/x64/include C:/hostedtoolcache/windows/Java_Adopt_jdk/8.0.292-10/x64/include/win32 C:/hostedtoolcache/windows/Java_Adopt_jdk/8.0.292-10/x64/include
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    C:/Users/RUNNER~1/AppData/Local/Temp/pip-req-build-_xlv4eex/_skbuild/win-amd64-3.7/cmake-install
-----------------------------------------------------------------

'
abhiTronix commented 3 years ago

@savadkv01 This may be a problem with Pycharm, I guess you could also just silence the warning in the IDE, by adding a noinspection comment.

# noinspection PyArgumentList
cap = cv2.VideoCapture(0)

More information here: https://stackoverflow.com/questions/39929166/cv2-python-videocapture0-unexpected-argument

savadkv01 commented 3 years ago

Hi, When I use python on command prompt also, same issue is getting. Screenshot_2

C:\Users\Support ACTA>python Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

import cv2 print(cv2.version) 4.5.3 cv2.VideoCapture(0) Traceback (most recent call last): File "", line 1, in TypeError: VideoCapture() takes no arguments

asmorkalov commented 3 years ago

Linux version works as expected:

~$ python3
Python 3.6.9 (default, Jan 26 2021, 15:33:00) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2 as cv
>>> qq = cv.VideoCapture(0)
>>> print(qq)
<VideoCapture 0x7f70094d7750>

I need some time to reproduce the same on Windows host and I'll come back.

asmorkalov commented 3 years ago

Windows works ok for me:

C:\Users\xperience>python -m pip install --upgrade opencv-python
Collecting opencv-python
  Downloading opencv_python-4.5.3.56-cp39-cp39-win_amd64.whl (34.9 MB)
     |████████████████████████████████| 34.9 MB 1.6 MB/s
Requirement already satisfied: numpy>=1.19.3 in c:\users\xperience\appdata\local\programs\python\python39\lib\site-packages (from opencv-python) (1.20.3)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.5.3.56
WARNING: You are using pip version 21.1.1; however, version 21.2.2 is available.
You should consider upgrading via the 'C:\Users\xperience\AppData\Local\Programs\Python\Python39\python.exe -m pip install --upgrade pip' command.

C:\Users\xperience>python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print(cv.__version__)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'cv' is not defined
>>> import cv2 as cv
>>> print(cv.__version__)
4.5.3
>>> cv.VideoCapture(0)
<VideoCapture 000002BBF4561A70>
>>>
Ibrahimshaikh1258 commented 11 months ago

I'm facing same problem try different options not solving the problem this comments useful. @asmorkalov Thanks for the solved the problem.