[project-opencv 01] I created three different projects with opencv after learning for one week

Subscribe to my newsletter and never miss my upcoming articles

I was trying to learn and develop some projects with the OpenCV library. If you didn’t know about what is OpenCV, go check it out! It is the highly optimised library focus on real-time application and you can play with it in python, c++ and java. So I have been researching the trend of the projects with OpenCV library, the current trend of the community focus a lot on feature detection, image processing and the drawing functions.

And I realised the flow of a usable project with OpenCV normally involved with three parts:

-feature detection (finding contours)

-image-processing (drawing the contours)

-the drawing functions (display it to the canvas)

After studying couple of hours, I started to create different functions and the majority of them involve finding contours, drawing the contours and display it to the canvas. So I created a virtual environment for these projects.If you want to try my work, you can clone my repo and play around with your webcam too! So if you want to use your webcam, you might want to change the following part of the code:

cap = cv2.VideoCapture(1)

Try 0 if you only have one webcam, and try 1 if you want to use another webcam.

The first project that I created is projectdrawer.py, my previous Microsoft webcam (vx-1000) is being used and it still works very well! (I spent almost an hour about installing the windows7 driver configuration of the webcam.)

So it involves different pieces of code. And I was using my light pink lighter as a controller. (Because I think it is the brightest object that I have in my room...)

螢幕截圖 2020-11-02 下午5.43.37.png

And I also created a project focusing on object recognition with car detection. (projectcar.py)

螢幕截圖 2020-11-02 下午5.48.18.png

So I was using a cascade classifier in this project car, so what is a cascade classifier? Well, according to Wikipedia:

Cascading classifiers are trained with several hundred "positive" sample views of a particular object and arbitrary "negative" images of the same size. After the classifier is trained it can be applied to a region of an image and detect the object in question. To search for the object in the entire frame, the search window can be moved across the image and check every location for the classifier. This process is most commonly used in image processing for object detection and tracking, primarily facial detection and recognition.

So I found some pre-trained cascading classifiers (some XML files) and using the XML files to create the classifier itself:

    #xml  classifier
    classifier = "Resources/cars.xml"

    #create the tracker
    car_tracker = cv2.CascadeClassifier(classifier)

You can play around with this project as well, it is very satisfying...

螢幕截圖 2020-11-02 下午6.20.58.png

I faced an issue with Github because the file size of my sample videos (including the one in the screenshot) is too large more than 100MB. You can put your video with the cars (any video with lots of cars) inside the /Resources folder and change the path in the following line:

cap = cv2.VideoCapture("Resources/cars2.mov")

It is very fun to play with and you can try it out too.

I will develop more projects with the OpenCV library! Stay tuned!

I hope you enjoy my first post on Hashnode, feel free to drop me an email about anything related to machine learning or artificial intelligence. My email is . You can also check all the codes in my Github or click the following URL: https://github.com/byronwongdev/project-opencv

No Comments Yet