[PYTHON] Try using OpenCV on Windows

It's more recent, but I wanted to touch Python and OpenCV, so I decided to build an environment. I will introduce it to Windows so that I can easily play at home in my spare time.

Introduction of WinPython

Apparently, using something called WinPython makes it easy to install the set of things you need on Windows.

At first, I tried installing the latest WinPython 3.5.4, but due to various reasons, I reinstalled 3.4.4. By the way, WinPython doesn't write to the registry, so if you want to uninstall it, just delete the directory. In conclusion, I don't recommend installing the latest version of WinPython.

Introduction of OpenCV

You can check the packages included in WinPython here. I thought that OpenCV was also included, but it was not included ...

That's why I will introduce OpenCV. You can download it normally and run the exe, but there seems to be an easier way.

Download the whl file from here, specify the whl file from the WinPython Control Panel, and click Install Packages. It should be OK, but if the version of WinPython is not supported, the installation will not be performed correctly. Please note that no message will be displayed at this time. From Winpython Command Prompt pip install whlfile If you do, an error message will be displayed, so if you think something is wrong, run it from the command prompt and check the error message.

This time I used the following two versions.

Confirmation of installation

You can start the IPython Qt Console and check the version as follows.

ivt


import cv2
cv2.__version__

'3.1.0' is returned.

Operation check

Now let's create a simple sample in Spyder and run it. Start Spyder.exe in the installation directory. Let's paste the following code and make it work. It is successful when the camera starts.

If a black screen is displayed, the default camera settings may be different, so try using cv2.VideoCapture (1). I tried it with two Thinkpads, but one was displayed correctly with 1 instead of 0.

cameratest.py


import cv2
import time

window = "push ESC key to stop this program"


if(__name__ == '__main__'):
   
    #Default camera is 0
    capture = cv2.VideoCapture(0)
    
    #Capture process
    while(True):
        key = cv2.waitKey(1)
        if(key == 27):
            print("close.")
            break
        
        #Image capture
        ret, img = capture.read()
        
        #If the import has not started, try again
        if(ret == False):
            print("Capture Failed.")
            break
        
        cv2.imshow(window, img)
           
        time.sleep(0.050)
    
    capture.release()
    cv2.destroyAllWindows()

Summary

This time, I built a python and OpenCV environment on Windows and started the camera. Next time, I would like to recognize the face in the video using the face detector provided as a sample.

Recommended Posts

Try using OpenCV on Windows
Notes for using OpenCV on Windows10 Python 3.8.3.
Try using Bash on Windows 10 2 (TensorFlow installation)
Try FEniCS on Windows!
Try Poerty on Windows
Try using E-Cell 4 on Windows 7 or Mac OS X
Try using Pillow on iPython (Part 2)
Build and install OpenCV on Windows
Try using ArUco on Raspberry Pi
Try using Pillow on iPython (Part 3)
Try installing OpenCV 3.0 on your AMI
Try using Tkinter
Install opencv on Mac using Anaconda Navigator
Try using docker-py
Python on Windows
Try using cookiecutter
Try using PDFMiner
Try using the camera with Python's OpenCV
Try using geopandas
Try using Selenium
Try using scipy
Try using pandas.DataFrame
Try using django-swiftbrowser
Try using matplotlib
Try using tf.metrics
Video processing using Python + OpenCV on Mac
Try using PyODE
Notes on installing Python3 and using pip on Windows7
Try using a QR code on a Raspberry Pi
Python: Try using the UI on Pythonista 3 on iPad
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Notes for using TensorFlow on Bash on Ubuntu on Windows
[Python] How to install OpenCV on Anaconda [Windows]
Pylint on Windows Atom
Linux (WSL) on Windows
Try using virtualenv (virtualenvwrapper)
Use pyvenv on Windows
[Azure] Try using Azure Functions
Anaconda on Windows Terminal
Try using virtualenv now
Install Anaconda on Windows 10
python basic on windows ②
Install python on windows
Try using W & B
Try using Django templates.html
Install pycuda on Windows10
[Kaggle] Try using LGBM
Try using Python's feedparser.
Try using Python's Tkinter
Build TensorFlow on Windows
Build XGBoost on Windows
Install pygraphviz on Windows 10
Use Ansible on Windows
Try NeosVR on Linux
Install Chainer 1.5.0 on Windows
Use QuTiP on Windows
Use pip on Windows
Notes on using Alembic
Try using Tweepy [Python2.7]
Try deepdream on Mac
Try using Pytorch's collate_fn