[PYTHON] Troubleshoot with installing OpenCV on Raspberry Pi and capturing

A memo when introducing OpenCV to Raspberry pi ...

environment

Preparation

$ sudo apt-get install python python-dev
$ sudo apt-get install python-numpy python-scipy python-matplotlib

Introduction of OpenCV

It's tedious to build and it takes time, so use apt-get I referred to this area Build an OpenCV-Python environment on Raspberry Pi B + Install OpenCV and Python on your Raspberry Pi 2 and B+

$ sudo apt-get install libopencv-dev

Apt-get Python package

$ sudo apt-get install python-opencv

I think it will take about 5 minutes.

Source of capture

I tried it with this source.

capture.py


#coding:utf-8
import cv2
color = (0, 2, 2)

def capture_camera(mirror=True, size=None):
    cap = cv2.VideoCapture(1)
    while True:
        ret, frame = cap.read()

        if mirror is True:
            frame = frame[:,::-1]

        if size is not None and len(size) == 2:
            frame = cv2.resize(frame, size)

        cv2.imshow('camera capture', frame)
        k = cv2.waitKey(1)
        if k == 27:
            break
        elif k== 'q':
        	break

    cap.release()

    cv2.destroyAllWindows()

capture_camera()

Let's move

If you think

GdkGLExt-WARNING **: Window system doesn't support OpenGL.

Error message! It seems different if you think that vnc is the cause.

Fix For the time being, this was the solution.

sudo apt-get install libgl1-mesa-dri

And

sudo reboot

It worked safely. It also worked on vnc.

Finally

I referred to this area. Trouble with Raspberry Pi camera and OpenCV Troubleshooting

Recommended Posts

Troubleshoot with installing OpenCV on Raspberry Pi and capturing
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Install OpenCV4 on Raspberry Pi 3
Record temperature and humidity with systemd on Raspberry Pi
Detect mask wearing status with OpenCV and Raspberry Pi
MQTT on Raspberry Pi and Mac
OpenCV installation procedure on Raspberry Pi
Create a web surveillance camera with Raspberry Pi and OpenCV
Pet monitoring with Rekognition and Raspberry pi
Capturing images with Pupil, python and OpenCV
Programming normally with Node-RED programming on Raspberry Pi 3
Working with sensors on Mathematica on Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
MQTT RC car with Arduino and Raspberry Pi
Power on / off your PC with raspberry pi
Play with your Ubuntu desktop on your Raspberry Pi 4
Get temperature and humidity with DHT11 and Raspberry Pi
Connect to MySQL with Python on Raspberry Pi
GPGPU with Raspberry Pi
Cython on Raspberry Pi
Make a thermometer with Raspberry Pi and make it visible on the browser Part 3
Machine learning with Raspberry Pi 4 and Coral USB Accelerator
Build an OpenCV4 environment on Raspberry Pi using Poetry
Run LEDmatrix interactively with Raspberry Pi 3B + on Slackbot
Easy IoT to start with Raspberry Pi and MESH
Try debugging Python on Raspberry Pi with Visual Studio.
Measure temperature and humidity with Raspberry Pi3 and visualize with Ambient
Installation of Docker on Raspberry Pi and L Chika
Install pyenv on Raspberry Pi and version control Python
Getting Started with Yocto Project with Raspberry Pi 4 and WSL2
Display USB camera video with Python OpenCV with Raspberry Pi
Control music playback on a smartphone connected to Raspberry Pi 3 and bluetooth with AVRCP
Build a server on Linux and local network with Raspberry Pi NextCloud and desktop sharing
Mutter plants with Raspberry Pi
Use NeoPixel on Raspberry Pi
Install TensorFlow 1.15.0 on Raspberry Pi
Easy introduction to home hack with Raspberry Pi and discord.py
[Note] Installing vmware ESXi on Arm Fling on Raspberry Pi 4B
Create an LCD (16x2) game with Raspberry Pi and Python
I tried connecting Raspberry Pi and conect + with Web API
Production of temperature control system with Raspberry Pi and ESP32 (1)
Measure and compare temperature with Raspberry Pi and automatically generate graph
Shining life with Python and OpenCV
[Raspberry Pi] Stepping motor control with Raspberry Pi
Control the motor with a motor driver using python on Raspberry Pi 3!
Use vl53l0x with Raspberry Pi (python)
Neural network with OpenCV 3 and Python 3
raspberry pi 4 centos7 install on docker
Install OpenCV and Chainer on Ubuntu
Serial communication with Raspberry Pi + PySerial
Introducing OpenCV on Mac with homebrew
Christmas classic (?) Lighting a Christmas tree with Raspberry Pi and Philips Hue
OS setup with Raspberry Pi Imager
Try using ArUco on Raspberry Pi
Make a thermometer with Raspberry Pi and make it viewable with a browser Part 4
Make a Kanji display compass with Raspberry Pi and Sense Hat
Weighing instrument using raspberry pi and hx711 (GUI display on Tkinter)
VPN server construction with Raspberry Pi
Try moving 3 servos with Raspberry Pi
Power on / off Raspberry pi on Arduino