fabiochiu/medium-articles huggingface dataset:
Can you compile OpenCV Source (in arm64) on Apple M1?
By: Raymond Lo
Tags: Source Code, Apple M1, Opencv, Apple M1 Chip

Another Simple Answer: YES!

In my last post, I tried to get OpenCV — x86-64 running on Apple M1.

Simple answer: Yes, OpenCV can be compiled in x86-64 with Rosetta.

Here I just compile again natively.



cd opencv

mkdir build_arm64

cd build_arm64

cmake ../

make -j 9 git clone https://github.com/opencv/opencv cd opencvmkdir build_arm64cd build_arm64cmake ../make -j 9

Again, a little while later. It is compiled successfully.

Ok, basically nothing to see here. It all works as expected. In conclusion, I could switch between two architectures without thinking much about it. If you are linking applications using dynamic linking, then it will be a management nightmare. Good luck here!
Count Finger using OpenCV
By: Ramji Balasubramanian
Tags: Mini Projects, Contour, Opencv, Segmentation

Background Detection

In first step we are going to find the background image and calculates the weighted sum of the image and destination. so that the destination will be a running sequences of frames.

def cal_accum_avg(frame,accumulated_weight):



global background



if background is None:

background = frame.copy().astype(‘float’)

return None



cv2.accumulateWeighted(frame,background,accumulated_weight)

Segmenting the ROI (Hand)

In second step, the background image will be subtracted from the current image. Hence the Region of Interest will be detected using Contours in black and white image.

def segment(frame,threshold = 25):



diff = cv2.absdiff(background.astype(‘uint8’),frame)



ret,thresholded_img = cv2.threshold(diff,threshold,255,

cv2.THRESH_BINARY)



contours,hierarchy = cv2.findContours(thresholded_img.copy(),

cv2.RETR_EXTERNAL,

cv2.CHAIN_APPROX_SIMPLE)



if len(contours) == 0:

return None



else:

#Assuming the largest external contour in roi is the hand



hand_segment = max(contours,key = cv2.contourArea)



return (thresholded_img,hand_segment)

Counting Fingers

The main tricky part is our final stage, now your hand is detected but to count the numbers based on your fingers we still miss to segment separate fingers. Only then when one finger is folded we can use keep a track and count it. To do that we are going to use Convex hull function. Using Convex hull we wil be able to find the extreme point of your detected hand and then based on contours and extreme positions our job will become easier to count.

#Function to count fingers using Convexhull

def count_fingers(thresholded_img,hand_segment):



conv_hull = cv2.convexHull(hand_segment)



#most extreme top,bottom,left and right points

top = tuple(conv_hull[conv_hull[:, :, 1].argmin()][0])

bottom = tuple(conv_hull[conv_hull[:, :, 1].argmax()][0])

left = tuple(conv_hull[conv_hull[:, :, 0].argmin()][0])

right = tuple(conv_hull[conv_hull[:, :, 0].argmax()][0])



#finding center point

cx = (left[0] + right[0]) // 2

cy = (top[1] + bottom[1]) // 2



#calculate distance from center to all extreme points

distance = pairwise.euclidean_distances([(cx,cy)],

Y=[left,right,top,bottom])[0]



#calculate one of the max distance

max_distance = distance.max()



#create circle

radius = int(0.8 * max_distance)

circumference = (2 * np.pi * radius)



circular_roi = np.zeros(thresholded_img.shape[:2],dtype=’uint8')



cv2.circle(circular_roi,(cx,cy),radius,255,10)



circular_roi = cv2.bitwise_and(thresholded_img,thresholded_img,

mask = circular_roi)



contours,hierarchy= cv2.findContours(circular_roi.copy(),

cv2.RETR_EXTERNAL,

cv2.CHAIN_APPROX_NONE)



count = 0



for cnt in contours:

(x,y,w,h) = cv2.boundingRect(cnt)



out_of_wrist = ((cy + (cy * 0.25)) > (y + h))



limit_points = ((circumference * 0.25) > cnt.shape[0])



if out_of_wrist and limit_points:

count += 1



return count

We have all the necessary modules to start counting our fingers, now will start captures our own video and start counting.
Object Tracking Using OpenCV
By: Ramji Balasubramanian
Tags: Opencv, Object Detection, Object Tracking, Basics

Steps followed to track the ball from the chosen video

Step 1: Read the video frame by frame using cv2.VideoCapture()

Step 2: find the threshold/ color for the ball you wanna track (I followed a trail and error method)

Step 3: At every frame, look for the specified color range and make it white and rest all black (binary image conversion)

Step 4: Find the contours and take only the region with larger area.

Step 5: Since this is ball tracking I tried to find the center of the circle and drawn a circle.

Step 6: Draw circle with respect to center captured. That’s it. Doesn't is look simple?
Image Processing Best Practices — C++ Part 3
By: Soubhi Hadri
Tags: Image Processing, Coding Interviews, Cplusplus, Computer Vision, Opencv

Closest Person Face:

Now, let us shift gears to work on a different task and leave those tiring filters implementation. The new task is to find the closet person’s face to the camera. The first step is to detect the faces in the image. This is a well-studied task and it is known as Face Detection. There are many ways to solve this problem starting from OpenCV Harr Cascade Classifier and ending with many Deep Learning Models for face detections. The main difference between all these methods can be categorized under three factors: model size, accuracy and speed. Since the focus for this exercise is not about the face detections, we will utilize Harr Cascade Classifier from OpenCV. So, how can we get the closest person’s face to the camera after detecting all the faces in the image? Check the following animated picture and answer yourself. An animated image is worth a thousand words, right?

When the person is closer to the camera, the face area is bigger. So, getting the face with the biggest area size is equal to getting the closest face to the camera. Of course, this assumption is not 100% true and does not work when people are very close to each other because of the face size and the model accuracy. We won’t consider those situations in our implementation.

The Code:

Code Explanation:

Line 3–10: Create an OpenCV CascadeClassifier and load the model. You can find the model here. Line 11: Load the image in which we want to find the closest face to the camera. Line 16: The detection operation. Line 19–26: Loop through the detected faces and find the one with the maximum area. Also, draw a white rectangle around each face the detector was able to find. Line 28–33: Draw a red rectangle around the closest face.

The Result:

It is clear that the closest face has the red rectangle, so we achieved our goal. We can notice as well, that the detector missed a few faces, which means that we need to look into more accurate models for face detection (which is outside the scope of this article).

Bye Bye:

This is the last article in this series unless someone suggest ideas to write about. Do not hesitate to do that :)

One final note: the solutions I have provided in this article may not be fully optimized. Our goal was to practice together, so do not hesitate to suggest any modifications that can be done. Also, feel free to provide any ideas or share any concerns
Segmentation of Products using OpenCV — Part 2
By: Ramji Balasubramanian
Tags: Computer Vision, Segmentation, Opencv, Basics

Detection of Article

How can we detect the articles?. One way can be to use a simple contour detection technique to detect the outer regions of the article and approximating the detected contours to form a rectangle box. The another way can be to use a pretrained Deep Learning(DL) to detect the regions directly. The usage of DL and simple basic OpenCV methods are based on what problem statement you are working on. Say you wanted to segment human, signal post, trees, cat, car, cycle, etc., in the application of autonomous car, there we need to go for DL method because the car has to act on every few seconds frame to drive you safely to the destination. In this application, we are just trying to detect 5 articles from a standard image so I preferred to go for former.

Dilation is done to enhance the canny detected image
Segmentation of Products Using OpenCV- Part 1
By: Ramji Balasubramanian
Tags: Computer Vision, Segmentation, Opencv, Basics

Segmentation can be defined as highlighting the interested region in any space. It can be finding a nice sentence from a book, potholes in road, abnormal region in X-Ray, Rotten fruits in shops or any products on shelf in retail shops.

Here in this article, we are going to experience how a basic segmentation problem works with basic simple coding using OpenCV. So, I have taken an image which has 5 products in it (Lays, Kurkure, Top Yumm and Pepsi) and tried to segment one product. For segmenting the region we have to follow few steps. Firstly detecting the products from the image using Contours and edge detection as we saw in my previous article, Then Segment only lays region and black out other products.
Signature Recognition Using OpenCV -Part 2
By: Ramji Balasubramanian
Tags: Morphology, Computer Vision, Opencv, Concepts For Beginners

In my previous article, we tried to detect the signature region from a pdf using contour and draw a rectangle covering the signature region. You can read about it in Part 1.

As we said in Part 1, we are going to cover Morphological Transformation to remove the extra white spaces from the cropped signature and Structural Similarity Index to compare the similarity between original signature image and identified signature image.

Cropping Signature Region from PDF

To crop an image we need the coordinates of top left corner, width and height of the rectangle are collected from Part 1.
Multi-class Image Classification in Teachable Machine and its Real Time detection with OpenCV Python
By: Hari Krishnan U
Tags: Python, Computer Vision, Opencv, TensorFlow, Teachable Machine

ML algorithm classifies the object(here Teddy 🧸)

In this blog, we can see how to do multi-class image classification in Teachable Machine and its Real Time detection with OpenCV Python.

At first, Go to Teachable Machine and Choose a new Image Project. Add image samples in the various classes as required and Choose Train Model. Now, Use the Preview feature to verify that your model is accurate. Choose Export the model → Select Tensorflow. Check Model conversion type as Keras and download your model into your local computer. A zip file named converted_keras is downloaded. Unzip the file contents into a working directory.

The working directory now contains labels.txt (which contains information about classes we have)and keras_model.h5 (which is the ML model trained in tensorflow by Teachable machine).

Now, Create a requirements.txt file in the working directory, with the following content to install the required dependencies.

requirements.txt

We have the names of the labels that is to be classified in the labels.txt . The below function gen_labels() generates a dictionary containing the label names as its values and corresponding numbers(as defined by the ML model) as the keys.

process_labels.py

The below python file main.py contains the integration of the model trained by the Teachable Machine and OpenCV Python to enable Real-time detection. The below file also contain code lines from the Official Teachable machine Tensorflow Keras code snippet.

main.py

So we have successfully built our Real-Time Image Classifier. I hope this blog has provided some value to you. The entire code is available in GitHub in this repo. Do give it a star✨, if you find it useful.

Gain Access to Expert View — Subscribe to DDI Intel
OpenCV kütüphanesi ile Görüntü İşleme(Android)-2
By: Pelin Tunçel
Tags: Android App Development, Opencv

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
MagicLeapWithDlibFaceLandmarkDetectorExample試してみた
By: Sadao Tokuyama
Tags: Magic Leap 1, マジックリープ, Magic Leap One, Opencv, Magic Leap

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
Face Detection with Python using OpenCV
Tags: Opencv Python, Facedetection, Computer Vision, Cascadeclassifier, Opencv

Face detection is a computer vision technology.

It helps to locate and visualize human faces in digital images.

Pre-requisite

Knowledge of Numpy and Matplotlib is essential before working on the concepts of OpenCV.

Install following packages before installing OpenCV.

Python

Numpy

Matplotlib

OpenCV already contains many pre-trained classifiers for face, eyes, smile etc.

These XML files are stored in /OpenTemp/opencv-3/data/haarcascades/ folder.

Now let’s create face detector with OpenCV.

First we need to load the required XML classifiers.

Then load our input image in grayscale mode.

Final Code is as follows :

import cv2

import numpy as np

from matplotlib import pyplot as plt

face_cascade=cv2.CascadeClassifier(“../OpenTemp/opencv-3/data/haarcascades/haarcascade_frontalface_default.xml”)

# load image to be identified

img=cv2.imread(“../Picturefolder/girl.jpeg”)

gray_img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

faces=face_cascade.detectMultiScale(gray_img,scaleFactor=1.05,minNeighbors=2)

for x,y,w,h in faces:

imag=cv2.rectangle(gray_img,(x,y),(x+w,y+h),(0,255,0),3)

resized=cv2.resize(imag,(int(imag.shape[1]),int(imag.shape[0])))

plt.imshow(resized)

plt.show

# waitKey(0) then the window shows the image until you press any key on

# keyboard

cv2.waitKey(0)

cv2.destroyAllWindows()

Conclusion:

It took almost 5 minutes to write the code.

Enjoy coding!!
Canny Edge Detector
By: Krithika Nagi
Tags: Python, Canny Edge Detection, Opencv, Edge Detection, Edge Computing

Developed in 1986 by John F. Canny, Canny Edge Detection algorithm is an algorithm of multi-stages. It identifies the key structures in an image/video by implementing 5-stage process.

The Canny edge detection algorithm mainly follows:

Noise reduction Gradient calculation Non-maximum suppression Double threshold Edge Tracking by Hysteresis.

We are gonna look at its implementation with Python’s Opencv library. My input image —

Firstly import opencv library:

Since, I want a trackbar in my output window, I will be introducing a function “nothing” only because we need it as an argument in the next few lines of code

Now we create trackbars of two kinds, one named “upper” and another “lower.”

Now we read the input image, make sure to mention the path correctly,

Convert the image to grayscle using inbuilt function from cv2

Now we will run a while loop to ensure the output is displayed properly and we use the canny edge detector fucntion whose parameters are “ gray “ which the above grayscale image, and it takes two more arguments namely “x”, “y” which are the trackbar thresholds that is obtained through the slider in the output window.

By runing the code and after setting the trackbar, we get the output as shown below,

Resources:
Face Detection in Python Using a Webcam
By: Vaibhav Hariramani
Tags: Facerecognitioncamera, Python, Facedetection, Opencv

The Code

Let’s dive straight into the code, taken from this repository.

import cv2

import sys cascPath = sys.argv[1]

faceCascade = cv2.CascadeClassifier(cascPath) video_capture = cv2.VideoCapture(0) while True:

# Capture frame-by-frame

ret, frame = video_capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = faceCascade.detectMultiScale(

gray,

scaleFactor=1.1,

minNeighbors=5,

minSize=(30, 30),

flags=cv2.cv.CV_HAAR_SCALE_IMAGE

) # Draw a rectangle around the faces

for (x, y, w, h) in faces:

cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2) # Display the resulting frame

cv2.imshow('Video', frame) if cv2.waitKey(1) & 0xFF == ord('q'):

break # When everything is done, release the capture

video_capture.release()

cv2.destroyAllWindows()

Now let’s break it down…

import cv2

import sys cascPath = sys.argv[1]

faceCascade = cv2.CascadeClassifier(cascPath)

This should be familiar to you. We are creating a face cascade, as we did in the image example.

video_capture = cv2.VideoCapture(0)

This line sets the video source to the default webcam, which OpenCV can easily capture.

NOTE: You can also provide a filename here, and Python will read in the video file. However, you need to have ffmpeg installed for that since OpenCV itself cannot decode compressed video. Ffmpeg acts as the front end for OpenCV, and, ideally, it should be compiled directly into OpenCV. This is not easy to do, especially on Windows.

while True:

# Capture frame-by-frame

ret, frame = video_capture.read()

Here, we capture the video. The read() function reads one frame from the video source, which in this example is the webcam. This returns:

The actual video frame read (one frame on each loop) A return code

The return code tells us if we have run out of frames, which will happen if we are reading from a file. This doesn’t matter when reading from the webcam, since we can record forever, so we will ignore it.

# Capture frame-by-frame

ret, frame = video_capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = faceCascade.detectMultiScale(

gray,

scaleFactor=1.1,

minNeighbors=5,

minSize=(30, 30),

flags=cv2.cv.CV_HAAR_SCALE_IMAGE

) # Draw a rectangle around the faces

for (x, y, w, h) in faces:

cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2) # Display the resulting frame

cv2.imshow('Video', frame)

Again, this code should be familiar. We are merely searching for the face in our captured frame.

if cv2.waitKey(1) & 0xFF == ord('q'):

break

We wait for the ‘q’ key to be pressed. If it is, we exit the script.

# When everything is done, release the capture

video_capture.release()

cv2.destroyAllWindows()

Here, we are just cleaning up.
Social Distancing with OpenCV and CUDA in C++
By: Kirill Mityugin
Tags: Social Distance, Dnn, Opencv, Cuda

In this example I have connected to street webcam in Yalta and detecting social distance violations in real time with CUDA acceleration.

// Only one class for this detection

vector<string> class_names{ “person” }; // Webcam live stream

string video = “http://91.223.48.19:557/cgueSCEI?container=mjpeg&stream=main";

Calculate distance between pairs of objects (find center of rectangle)

Then mark violators with Red label and count in one frame:

vio_ss << “Violators: “ << violators.size();

Full source code in C++:

https://github.com/Mityugin/cmd-Social-Distancing-with-OpenCV
Custom OpenCV with Anaconda3 and PyCharm on Ubuntu
By: Pawel L.
Tags: Machine Learning, Computer Vision, Opencv, Programming, Linux

Photo by Cookie the Pom on Unsplash

This post will cover a method to build OpenCV library from the sources and use it with Anaconda3 environment. The integration with PyCharm IDE that properly autocomplete the code of the built library will be also introduced.

Although Anaconda comes with a prebuilt OpenCV package, there are situations that you may want to include special features that are not available in the general builds like non free algorithms or Qt/GTK support. Also building from sources allows to have the newest OpenCV version with no need to wait until the official build appears.

I’ll describe the process to build OpenCV with Contrib module on Ubuntu 18.04 LTS system, but it should work on other Linux distributions. If you don’t need Contrib module, just skip the steps related to it and modify cmake arguments list. The description is focused on making OpenCV integration with Anaconda3 and PyCharm so I’ll omit or describe shortly other steps like OpenCV building preparation or creating a project in PyCharm.

I used OpenCV 4.5 and Python 3.8.5 as of November 2020. Anaconda3 is assumed to be installed in the default location.
End to end Mask detection. Detect face with mask or without mask…
Tags: Python, Machine Learning, Opencv, Face Mask Detection, Deep Learning

2.Data Preprocessing

Before we process data, let structure our data in the right folder with the right name.

For this we have two option:

Use TensorFlow image_dataset_from_directory.

load CSV file.

Here we choose to load from a CSV file

In this dataset, the CSV file is not included so we have to generate through image data.

For that, we change the image name to withmask and withoutmask.

For Withmask

# importing os module

import os



# Function to rename multiple files

def main():

for count, filename in enumerate(os.listdir("DATASET/")):

dst ="withmask." + str(count) + ".jpeg"

src ='DATASET/'+ filename

dst ='DATASET/'+ dst

# rename() function will

# rename all the files

os.rename(src, dst)



# Driver Code

if __name__ == '__main__':

# Calling main() function

main()

For Withoutmask

# importing os module

import os



# Function to rename multiple files

def main():

for count, filename in enumerate(os.listdir("New folder/")):

dst ="withoutmask." + str(count) + ".jpeg"

src ='New folder/'+ filename

dst ='New folder/'+ dst

# rename() function will

# rename all the files

os.rename(src, dst)



# Driver Code

if __name__ == '__main__':

# Calling main() function

main()

now move all generated images into one folder and then create a pandas data frame

import pandas as pd

filenames=os.listdir("FULL_DATA/")

categories=[]

for f_name in filenames:

category=f_name.split('.')[0]

if category=='withmask':

categories.append('withmask')

else:

categories.append('withoutmask')

df=pd.DataFrame({

'filename':filenames,

'labels':categories

})

DataFrame

Save data frame into CSV file.

Now data is in the right structure we can load data

Read CSV file

# Import pandas import pandas as pd labels_csv = pd.read_csv("PATH TO CSV FILE")

Prepare label

import numpy as np labels = labels_csv["labels"].to_numpy() labels

Turn label into an Array of Boolean

# Find the unique label values unique_category = np.unique(labels) len(unique_category) boolean_labels = [label == unique_category for label in labels]

Create a validation set with train_test_split

# Setup X & y variables X = filenames y = boolean_labels # Let's split data from sklearn.model_selection import train_test_split # Into train and valid X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=2509) len(X_train), len(X_val), len(y_train), len(y_val)

Turning images into Tensor

# Define image size

IMG_SIZE = 224



# Function

def process_image(image_path, image_size=IMG_SIZE):

"""

Takes an image file path and turns the image into a Tensor.

"""

# Read in an image file

image = tf.io.read_file(image_path)

# Turn the jpg image into numerical Tensor with 3 colour #channel(RGB)



image = tf.image.decode_jpeg(image,channels=3)

# Convert the color channel values to (0-1) values

image = tf.image.convert_image_dtype(image,tf.float32)

# Resize the image to (224,224)

image = tf.image.resize(image, size=[image_size,image_size])



return image

Turning data into Batches
(OpenCV)bitwise_and 的mask通俗理解[轉錄]
By: Ryan Lu
Tags: Opencv

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
(OpenCV)前景／背景分離技術[轉錄]
By: Ryan Lu
Tags: Opencv

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
💣 Face Detection using Python and OpenCV for Beginners
By: Ali Cenk Baytop
Tags: Python, Opencv, Face Recognition

OpenCV & Python

In this post I’m going to share about the easiest and most basic face detection. And also I‘m going to use Haar Cascade classifier that which is one of the most famous classifiers.

💻 Let’s begin, if you don’t have OpenCV library, you can install it with that.

pip install opencv-python

Then open your IDE which is doesn’t matter. (I used Visual Studio Code)

1) Import OpenCV library:

2) Load Haar Cascade classifier:

You can download xml files from here.

3) Create your detect function:

Defining the function and determinig the parameter

2. Converted photograph BGR to Gray so what is that?

Reduced the number of channels so the computer can process faster.

3. MultiScale Detection for face, the first parameter is input image, the second is the scale factor specifies how much the image size is reduced with each scale, and the third is minimum neighbours specifies how many neighbors each candidate rectangle should have to retain it.

4. Corner points of scaled face

5. to draw a rectangle in the faces ->(255,0,0) is blue and 2 is thickness

6. Region of interest for gray photo

7. Region of interest for colorful photo

8. Same with third line

9. Corner points of scaled eyes

10. to draw a rectangle in the eyes

11. Output of this function

4) Read, detect and show photograph

Read image Enter into detect function Save new picture to your folder

Result:

All codes for picture:

How to run face detector in webcam?

How to run face detector in video?

In brief, I have explained How we can develope face detection using python and opencv. If you have question or something on your mind you can communicate with me on Linkedin. GitHub for this project.

Keep having fun, developing and living 🙂
When Newbies play with computer vision and Guitars? Going Zero to Hero.
By: Tanush Mahajan
Tags: Guitar Chords, Computer Vision, Augmented Reality, Opencv, Guitar

1Stop Logo

The Start:

The journey starts with me and 3 other crazy guys who agreed to make a project together based on computer vision having zero knowledge on the topic in the span of 4 months.

Upon brainstorming through a ton of Ideas and having a passion for playing guitar, we all agreed to make an app that would significantly improve the way that a beginner learns guitar.

The “Why” of it all:

Our App solves some of the major problems that beginners face while first starting to learn Guitar like:

1. Finding the correct version of the chords,

2. Difficulty in reading different chord notation,

3. It’s extremely FUN!! to see the chords displayed in real time etc.

How it works?

Our app uses an algorithm developed by using techniques in computer vision and displays whichever chord that user wants to play on the guitar in real time.

User Interface of 1Stop

Learning Guitar using our app is as simple as selecting the chord you want to learn and then pressing the show chord button to display results.

As someone once said — “It’s that easy BRUH!”

Advice for fellow developers who want to get into computer version:

Learn Python. Python is really easy to grasp and it has quite powerful libraries when it comes to data processing in this case video and image processing. But you can choose other languages as well! Start learning OpenCV. Learn basic snippets like how to read input video from a cam, how to convert that input video into frames, and how to display the processed video feed and save it. Learn some basic principles like thresholding, image filtering, edge detection, contour detection and try to write small programs to apply and test them. Choose a Project: Choose any project that would implement some basic computer vision principles you can google it or maybe even commit some dangerous mistakes like choosing a project of your own projects! Even if you aren’t able to finish the project you will learn a lot by actually writing your own code.

“Journey of a thousand miles, begins with a single step” — Lao Tzu.

In our journey me and my team mates learned a lot about computer vision techniques and we had a lot of fun building this super fun and super awesome guitar learning tool for you guys and if we can make this amazing app in 4 months without having an iota of knowledge on the topic, so can you!
Create FAST recognition object detection in the live time on the Raspberry Pi + OpenCV + TensorFlow Lite
By: Alex G.
Tags: Python, Data Science, Machine Learning, Opencv, Object Detection

Note before you start:

So, Let’s start :)

Hardware preparation:

Software preparation:

1 preparing VNC (if you have)

If you go to VNC Server Options (right-click on the VNC status icon in the top right) and check to Enable direct capture mode on the Troubleshooting page. This will allow you to see the camera output via VNC. Like on the screenshots:

2 install special version opencv-contrib-python==4.1.0.25

python3 -m pip install opencv-contrib-python==4.1.0.25

3 Check python version, it should be 3.7

python3 --version

4 Download Tensorflow Lite from here

python3 -m pip install https://github.com/google-coral/pycoral/releases/download/release-frogfish/tflite_runtime-2.5.0-cp37-cp37m-linux_armv7l.whl

5 Create directory

mkdir -p ~/tflite/object_detection/coco_ssd_mobilenet_v1

cd ~/tflite/object_detection

6 Download Pre-Trained Model

7 Unzip Pre-Trained Model

unzip coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip -d coco_ssd_mobilenet_v1

8 Run object detection script

User EdjeElectronics has example python script for object detection TFLite_detection_webcam.py and these code is based off the TensorFlow Lite image classification example at here. So just run this script for run fast object detection.

9 You should see something like that

FAST recognition object detection in the live time FAST recognition object detection in the live time (Photo,GIF by Author) https://github.com/oleksandr-g-rock/simple_object_detection/blob/main/1_Q_1L5w2tKI3goJ6INmqOfQ.gif

Result:

In this article, we created FAST recognition object detection in the live time on the Raspberry Pi. We improved speed o x2. So I guess it’s a good result.
[Python]OpenCV기초 — ROS. #목적
Tags: Ros, Python, Opencv

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
How to start programming Computer Vision with OpenCV and CUDA in Windows 10, Visual Studio 2019 C++. Part 2
By: Kirill Mityugin
Tags: C, Gpu, Cuda, Opencv, Vs2019

In Part 1 we have created first app for Computer Vision in C++ Visual Studio 2019 streaming live video from IP Camera and detecting objects but perfomance on CPU about 1–2 FPS is not acceptible for real time processing.

Let’s add GPU acceleration with CUDA technology in our project and compare how it works on sample video.

Install latest Nvidia driver for your graphics card Install CUDA toolkit and cuDNN dll’s — here is full guide:

3. Now you need to build OpenCV from source with CUDA support (it’s a long story) or just download ready builds for your version. This guy doing great job:

https://jamesbowley.co.uk/downloads/

Extract both DEBUG and RELEASE archives to separate folders in C:\opencvcuda:

4. Change system PATH variable and add dependencies to your project:

C:\opencvcuda\DEBUG\install\x64\vc16\bin and C:\opencvcuda\RELEASE\install\x64\vc16\bin

Add to PATH:

C:\opencvcuda\DEBUG\install\x64\vc16\bin C:\opencvcuda\RELEASE\install\x64\vc16\bin

Add to Visual Studio project properties separately for DEBUG and RELEASE configs. Example for RELEASE:

Visual Studio project properties

Include Directories:

C:\opencvcuda\RELEASE\install\include

Library Directories:

C:\opencvcuda\RELEASE\lib

Linker / Input / Additional Dependencies

for RELEASE:

opencv_world450.lib

for DEBUG:

opencv_world450d.lib

Now we can run our project with OpenCV CUDA backend:

Here we can change using CUDA or CPU in our source code

I have changed YOLOv4 models to full and input sample video in FullHD res to compare perfomance:

and also you can set CONFIDENCE_THRESHOLD = 0.3 parameter to filter detected objects.

Let’s test now.

CPU only Intel Core i5 9400f:

GPU Geforce RTX 2060 OC:

We have significant acceleration from 1–2 FPS to 22 FPS* that’s awesome!

*Update 1: Use DNN_TARGET_CUDA_FP16 instead of DNN_TARGET_CUDA it will increase rate from 25 FPS to 50–60 FPS

And what about testing again live video from IP camera with minimal settings?

We can set back tiny models and low res and even smaller input res for DNN:

blobFromImage(frame, blob, 0.00392, Size(inpWidth, inpHeight), Scalar(), true, false, CV_32F);

Width, Height of network’s input image 608 you can change to 416 or 320 it will increase rate but also decrease quality of detection.

What a dramatic change to 125–166 FPS*!

*Update 1: Use DNN_TARGET_CUDA_FP16 instead of DNN_TARGET_CUDA it will increase rate to 166–333 FPS

So using CUDA is a must for Computer Vision projects and next you can compare different DNN frameworks or detection quality settings.

Good luck with your experiments and Clap here…
How to start programming Computer Vision with OpenCV and IP Camera in Windows 10, Visual Studio 2019 C++. Part 1
By: Kirill Mityugin
Tags: C, Computer Vision, Opencv, Vs2019, Windows

It’s me)

There is a lot articles about developing CV in Python and/or Ubuntu OS everywhere, but not so much about C++ and VS2019 though it’s native for OpenCV libraries and most powerful language for Deep Learning & Computer Vision projects.

I’ll try to collect in this article what you need to start your first project detecting objects in real time with your IP(or USB) Camera.

First you need a powerful computer for such project because on my CPU Intel Core i5 9400f, 16Gb RAM, 1Tb M.2 NVMe SSD I get a couple FPS of CV that is unacceptable, next we will use GPU acceleration on CUDA cores, so you also need a powerful NVIDIA graphics card.

You have Windows 10, Visual Studio 2019 with C++ components, that’s great, I also developing helping tools in C# such as Discovery Tool for ONVIF IP cameras where you can get IP address for your next project

or just View your Camera with OpenCV in a beautiful WPF App:

To start programming in C++ with OpenCV you need:

Download binaries for Windows and source code from https://opencv.org/releases/ and place it usually to C:\opencv:

C:\opencv folder

2. There is great article how to add dependancies to your new project, so just not repeat it again look inside:

All you need to change there is file name for current version of library opencv_world420d.lib => opencv_world450d.lib

3. Source code for your first project so here it is:

https://gist.github.com/YashasSamaga — great author for OpenCV projects

as well as examples on OpenCV site

I changed it for my purposes so here is my variant:

You need download DNN model files yolov4-tiny.cfg and yolov4-tiny.weights (using here mini YOLOv4 models, you can change to full) and classes80.txt for classes list and place all to folder C:\TEMP

(All files you can download from my Github project)

classes80.txt looks like this so you can change what to detect (using 80, full list contains about 9k classes):

person

bicycle

car

motorcycle

cat

dog

My changes to original code:

using namespace cv;

using namespace std;

— for shorter names

std::ifstream class_file(“C:\\TEMP\\classes80.txt”);

— path to classes TXT file

string video = “rtsp://192.168.0.30:554/user=admin_password=tlJwpbo6_channel=0_stream=1.sdp?real_stream”;

VideoCapture source;

source.open(video.c_str()); auto net = cv::dnn::readNetFromDarknet(“C:\\TEMP\\yolov4-tiny.cfg”, “C:\\TEMP\\yolov4-tiny.weights”);

— URL to my IP cam RTSP stream (using 1.sdp for low resolution and higher FPS or 0.sdp for FullHD resolution and low rate)

— Path to YOLOv4 models, you can change here for full models or use another DNN framework

4. Don’t forget to change DEBUG in VS2019 to x64 and Run:

That’s all simple as it is folks :-) Next time I’ll use CUDA GPU accelerating in the same code, because 1–2 FPS not good))

Thanks for reading! Clap here if you liked it…
All You Need To Know About Open-Source OpenCV Projects And Libraries
By: Mrinal Walia
Tags: Python, Open Source, Computer Vision, Projects, Opencv

1. OpenCV

Github: 49, 800 stars and 40, 400 forks

Open-Source Computer Vision Library is an open source computer vision and machine learning software library built to provide a common infrastructure for computer vision applications.

The library has more than 2500 optimized algorithms for both classic and state-of-the-art computer vision and machine learning tasks. Using OpenCV we can:

detect and recognize faces,

identify objects,

classify human actions in videos,

track camera movements,

track moving objects,

extract 3D models of objects,

produce 3D point clouds from stereo cameras,

stitch images together to produce a high resolution image of an entire scene,

find similar images from an image database,

remove red eyes from images taken using flash,

follow eye movements,

recognize scenery and establish markers to overlay it with augmented reality, etc

2. OpenPose

Github: 19, 200 stars and 5, 800 forks

OpenPose is an open-source and free real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints with total of 135 keypoints on single images.

Built for multi platforms it supports :

2D real-time multi-person keypoint detection

3D real-time single-person keypoint detection

Calibration toolbox

Single-person tracking

Body and Foot Estimation

3-D Reconstruction Module (Body, Foot, Face, and Hands)

Body, Foot, Face, and Hands Estimation

Unity Plugin

Runtime Analysis

3. LearnOpenCV

Github: 12, 350 stars and 7, 800 forks

LearnOpenCV repository contains code for Computer Vision, Deep learning, and AI articles published on LearnOpenCV.com.

OpenCV is a library widely used due to its extensive coverage of the computer vision tasks, and availability to involve it in various projects, including deep learning using both Python and C++ programming languages.

This reposiroty contains blog links along with the code:

4. Rpa Python

Github: 1, 400 stars and 209 forks

RPA is a Python package for RPA(ROBOTIC PROCESS AUTOMATION).This tool was previously known as TagUI for Python.

RPA is Python’s simple and powerful API which makes robotic process automation fun and exciting.

It can be used to quickly automate repetitive time-consuming tasks, whether the tasks involve websites, desktop applications, or the command line.

Check out sample Python script, RPA Challenge solution, and RedMart groceries example.

5. PySceneDetect

Github: 1, 150 stars and 178 forks

PySceneDetect is an open-source and free command-line application and a Python library for detecting scene changes in videos, and automatically splitting the video into separate clips.

PySceneDetect can be used on its own as a stand-alone executable, with other applications as part of a video processing pipeline, or integrated directly into other programs/scripts via the Python API.

Examples and Use Cases

Here are some of the things people are using PySceneDetect for:
Setup OpenCV for python in any platform.
By: Yashod Perera
Tags: Opencv In Ubuntu, Opencv Python, Opencv Virtual, Opencv, Opencv Mac

Photo by Hitesh Choudhary on Unsplash

Setting OpenCV for python is piece of cake. Are you fed up with lots of tutorials. Let’s do it within 5 minutes.

First what we need is a virtual environment. venv is using for this tutorial and you can use any other tutorial as you preferred.

First let’s set up an virtual environment.

python3 -m venv virtual_environment

Then activate the virtual environment as follows.

source virtual_environment/bin/activate

Once the virtual environment is activated its’ name should be shown in brackets as in the third line.

Then install the OpenCV using one command. What using one command. Yes!

pip install opencv-python

Done!.

You can use OpenCV inside the virtual environment and you can install any other python packages also.
COVID-19: Face Mask Detector
Tags: Python, Machine Learning, Covid 19, Opencv, TensorFlow

A Machine Learning application for detecting faces wearing a mask, by using OpenCV, Keras/Tensorflow.

COVID-19 is spreading fast, in all globe. Wearing a mask can reduce its spreading, allowing to avoid the compliances of the virus.

Framework:

Computer vision can be used to develop a model for detecting in real-time if a face is wearing or not a mask. It requires a lot of techniques in order to build a model able to accomplish a such specific task. In particular, in addition to the base theory of Deep Learning and Machine Learning models, several important techniques are used:

Facial Landmarks: finding a dataset containing faces wearing a mask 😷 is not trivial. There exist a practical, fast and effective solution, it is Facial Landmarks. Facial Landmarks allows to detect specific region in a face, the so called Region of Interest (ROI), as eyes, nose, mouth, etc. In particular, in this project, starting from a dataset containing humans faces, it is obtained a new dataset containing humans faces wearing masks 🎭. First of all Facial Landmarks is used for individuating 👃 and 👄 in an image, and then a mask image is added in that position. In this way an artificial, yet real applicable, dataset is generated. Fine-Tuning/transfer learning: in order to solve the specific task the base model architecture, individuating with a MobileNet V2 (transfer learning) architecture ones, will be fine-tuning. Fine-tuning consists in adding some specific layers to a base model architecture and training just these added layers, using the weights of a pre-trained model, as initial weights. Data agumentation: during the training phase, will be added noise to images, in order to improve generalisation. This technique is known as data augmentation, where images are rotated, shifted or traslated on-the-fly, during training phase.

Let’s start:

After having created the dataset with human faces wearing a mask, the first step is about training our model.

Facial landmarks: fake mask added to an human face.

As already said, transfer learning and fine-tuning techniques are used. The base model architecture is the MobileNet V2, with weights trained over the ImageNet dataset. MobileNet V2 architecture allows to use the model even on embedded systems, as microprocessors and/or smartphone. This can reduce the cost of the infrastructure used for the service.
how to build a face-tracking with Raspberry and OpenCV
Tags: Face Tracking, Opencv, Raspberry Pi

This is my very first project on Raspberry. My motivations come from the article of Leigh Johnson :

It seems simple to start a project on Raspberry, so let’s start.

My github repos for this project : https://github.com/nguyenrobot/palt-tilt-cam

This project is realized in collaboration with Clément COSTE, one of my colleagues.

Part 1 — Build List

Raspberry Pi 4 Model B — 4GB

Pan-Tilt HAT for Raspberry Pi

Pi Camera v2 8MP

Micro-SD Card

Mini-HDMI Cable

Cable for Raspberry Pi Camera — Dimension : 457mm x 16mm (18" x 0.6")

USB-C Charger

USB-C External battery (optional by strongly recommended)

I spent roughly 100€ to get all necessary thing in France where we pay so much of TVA tax.

The choice of Pan-Tilt HAT is quite important. Because you have to find a way to control your Pan-Tilt HAT. I use the Pan-Tilt HAT from Waveshare which I have to spend sometimes to understand how to manually control the servo-motor via HAT by keyboard.

An external battery with USB-C output is highly useful for other projects on Raspberry in which your Raspberry must be mobile.
Intro to OpenCV CUDA
By: Winston Robson
Tags: Image Processing, Data Science, Cuda, Computer Vision, Opencv

Intro to OpenCV CUDA

Looks like we’re stuck in RGB.

Outline

On a Single Image

On a Series of Images

On Series of Images in Parallel with Dask Delayed

On a Single Image

First, we need to create GPU space ( gpu_frame ) to hold an image (as a picture frame holds a picture) before we can upload our image to the GPU.

Step 1: Upload

Next, load the image into memory with CPU ( screenshot ), and .upload() it to the gpu_frame (frame the image);

Image now in frame, we can start having fun.

Step 2: Have Fun

OpenCV CUDA functions return cv2.cuda_GpuMat (GPU matrices), so each result can be operated on without the user having to re- .upload() .

Let’s convert the image from RGB to BGR (OpenCV format), then resize it;

Note: the first function you call should be on the GPU matrix ( gpu_frame ) itself, not the image you’ve just uploaded. This will return a new GPU matrix. The original GPU matrix ( gpu_frame ) will continue to hold the original image until a new image is .upload() ed.

Step 3: Download

Now you might be wondering, “where’s the image?”

Well, it’s stuck on the GPU. We need to .download() it back to the CPU;

Note: .download() converts the image from cv.cuda_GpuMat to numpy.ndarray .

On a Series of Images

To process a new picture, you can simply .upload() that new picture to your existing GPU matrix. Images still must be loaded on CPU before being passed to GPU.

This time we added an inverted binary .threshold() to the preprocessing, here’s how they came out;

On Series of Images in Parallel with Dask Delayed

With Dask Delayed we can push the above loop into a Dask Delayed function and preprocess multiple series of images in parallel.

I also added in a 2nd .cvtColor() to grayscale the images, and switched the inverted binary threshold to a binary threshold.

Defining 2 lists of image files, we can now .compute() them side by side;

And here’s how they came out;

Fin

You can find the original images used in this story here on GitHub.

Thanks for reading. Please feel free to respond with any questions.

Continued Reading

References

Koriukina, Valeriia. “Getting Started with OpenCV CUDA Module.” Learn OpenCV, Learnopencv.com, 15 Sept. 2020, learnopencv.com/getting-started-opencv-cuda-modul.

McWhorter, Paul. “AI on the Jetson Nano LESSON 10: Installing OpenCV for Python 3.” Paul McWhorter — YouTube, Youtube.com/User/Mcwhorpj, 2 Nov. 2019, youtu.be/3QYayL5y2hk.

Pulli, Kari; Baksheev, Anatoly; Kornyakov, Kirill; Eruhimov, Victor. “Realtime Computer Vision with OpenCV.” Realtime Computer Vision with OpenCV — ACM Queue, Association for Computing Machinery, 22 Apr. 2012, queue.acm.org/detail.cfm?id=2206309.
Capture Image and Convert into PDF in Python
By: Vaibhav Mishra
Tags: Opencv, Python, Python3, Job Search

Coding is fun for programmers, But when you code in python that fun becomes double. So purpose of this blog is to spread fun everywhere.

There is multiple project where we need to capture the image and then we need to upload that image to cloud for some of our documents. I can say you a scenario where you need to use this blog, Suppose you are creating a job portal where you need to generate users details in PDF with his image then you can use this small piece of python code and save your time.
Homebrew 安裝 OpenCV4.5.0搭配 Xcode GUI
By: 周信閎 Hsin-Hung Chou
Tags: Xcode, Cpp, Opencv

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
Face Recognition With OpenCv
Tags: Classification, Computer Science, Computer Vision, Opencv, Deep Learning

While the world is moving towards touchless technologies, computer vision algorithms plays a key role in building such applications to reduce human interventions.

One such application is recognizing human faces. Without knowing, we all are an integral part of face recognition application in our daily lives, ranging from unlocking mobile with face recognitions, google photos grouping, facial recognition in surveillance, pay by face techniques, and many more.

This article will explain how to build a face recognition application that detects the faces and counts the faces based on gender using OpenCV.

Read more…!