OpenCV (Open Source Computer Vision Library) is a collection of BSD-licensed video / image processing libraries. There are many algorithms for image filtering, template matching, object recognition, video analysis, machine learning, and more.
Example of motion tracking using OpenCV (OpenCV Google Summer of Code 2015) https://www.youtube.com/watch?v=OUbUFn71S4s
Click here for installation and easy usage http://qiita.com/olympic2020/items/d5d475a446ec9c73261e
In order to track moving objects, it is necessary to first filter the image. This time, I will try edge detection using OpenCV.
The flow is as follows.
sample.py
import cv2
#Constant definition
ORG_WINDOW_NAME = "org"
GRAY_WINDOW_NAME = "gray"
CANNY_WINDOW_NAME = "canny"
ORG_FILE_NAME = "org.jpg "
GRAY_FILE_NAME = "gray.png "
CANNY_FILE_NAME = "canny.png "
#Load the original image
org_img = cv2.imread(ORG_FILE_NAME, cv2.IMREAD_UNCHANGED)
#Convert to grayscale
gray_img = cv2.imread(ORG_FILE_NAME, cv2.IMREAD_GRAYSCALE)
#Edge extraction
canny_img = cv2.Canny(gray_img, 50, 110)
#Show in window
cv2.namedWindow(ORG_WINDOW_NAME)
cv2.namedWindow(GRAY_WINDOW_NAME)
cv2.namedWindow(CANNY_WINDOW_NAME)
cv2.imshow(ORG_WINDOW_NAME, org_img)
cv2.imshow(GRAY_WINDOW_NAME, gray_img)
cv2.imshow(CANNY_WINDOW_NAME, canny_img)
#Save to file
cv2.imwrite(GRAY_FILE_NAME, gray_img)
cv2.imwrite(CANNY_FILE_NAME, canny_img)
#End processing
cv2.waitKey(0)
cv2.destroyAllWindows()
The forest in the foreground, the building in the middle, and the sky in the back were edge-extracted as such.
The original image
grayscale
Edge detection
Next, let's deal with videos. Try converting videos in real time with OpenCV
Recommended Posts