OpenCV - Open Source Computer Vision

15 Jun 2018

Ok - this guy has already built an app for real-time object recognition, see here: https://github.com/datitran/object_detector_app

You can play around with it for fun!

Edit: If in case anyone was wondering why the window can’t close properly… I suspect you need to press ‘q’ to exit.

However, as my purpose is quite different, I shall attempt to build my own video detection thingy based on the Tensorflow API (the frozen model first, then we shall see if I want to unfreeze the top layers and train it) LOL

Not going to be easy! First things first… how do I get my video into frames?

import numpy as np
import cv2

cap = cv2.VideoCapture('alligator_video.mp4') # you can change it to your video file

while(cap.isOpened()):
    ret, frame = cap.read()

    if ret == True:
        cv2.imshow('frame', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break
            
cap.release()
cv2.destroyAllWindows()

I’m just trying to get it to show each frame of the video for now… but somehow my video file can’t close at cap.release() which is strange. Guess I have to slowly learn from scratch and figure it out.

OpenCV, here I come!

https://docs.opencv.org/2.4/modules/contrib/doc/facerec/facerec_tutorial.html

Edit: This might be more helpful for general use: http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_setup/py_intro/py_intro.html#intro


On a side note, if anyone has any trouble installing opencv on python 3 (mine kept installing on python 2.7 and pip3 didn’t work), here’s what I used (thanks to my trusty personal advisor): python3 -m pip install opencv-python

And if anyone is ever curious what -m means: https://docs.python.org/3/using/cmdline.html