DEV Community

El Bruno
El Bruno

Posted on β€’ Originally published at elbruno.com on

#reTerminal – Installing OpenCV, and using a USB WebCam 🀳

Hi !

Let's start with some posts using reTerminal with a very simple scenario:

Connect a Camera to the device and show the camera feed in reTerminal display

The output is something similar to this one.

reterminal with a camera displaying the camera feed

And letΒ΄s start with the base code to run this, based on my previous posts on OpenCV (see references)

import os
import cv2
import time
# init camera
execution_path = os.getcwd()
camera = cv2.VideoCapture(0)
while True:
# Init and FPS process
start_time = time.time()
# Grab a single frame of video
ret, frame = camera.read()
# calculate FPS >> FPS = 1 / time to process loop
fpsInfo = "FPS: " + str(1.0 / (time.time() - start_time))
print(fpsInfo)
cv2.putText(frame, fpsInfo, (10, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1)
# Display the resulting image
cv2.imshow('Video', frame)
# Hit 'q' on the keyboard to quit!
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release handle to the webcam
camera.release()
cv2.destroyAllWindows()
view raw PythonWebCamFeed.py hosted with ❀ by GitHub

The main prerequisite to run this code is to have OpenCV installed. And this is a tricky process in a Raspberry Pi. I used to install all the necessary libraries and apps, and then build OpenCV in my device (see references).

Today I follow these steps to make this happens.

1st I install Virtual Environments to I can work in isolated modes for my tests. Run these scripts

sudo pip3 install virtualenv
virtualenv -p python3 camLabs
source camLabs/bin/activate</pre>
Enter fullscreen mode Exit fullscreen mode

Last line will activate my virtual environment.

Once I'm in the virtual environment, I can install OpenCV with the following command

sudo pip install opencv-contrib-python==4.1.0.25</pre>
Enter fullscreen mode Exit fullscreen mode

And run the quick test to validate the installation.

In the process I learned a couple of lessons about installation with amazing errors like these ones

error installing opencv on reterminal 2

error installing opencv on reterminal

At the end, the simple command to install OpenCV makes the magic!

References

Continue reading #reTerminal – Installing OpenCV, and using a USB WebCam 🀳

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (3)

Collapse
 
shinprog profile image
ShinProg (Logan Tann) β€’

For that length, I'd prefer having the whole post here instead of a link to your blog :(

Collapse
 
elbruno profile image
El Bruno β€’

I managed to have the full content sync from my blog to here :D

Collapse
 
elbruno profile image
El Bruno β€’

Thanks for the feedback ! I'm using the automated cross-post process. I'll try to ffigure out how to do the full cross-posting, instead of the header.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay