My Project 1:
Freedom Fighter Recognition System using OpenCV:
This project uses the concept of template matching (in OpenCV) and object detection.
The project takes a source image and a template/patch. Here the source image is a collage of freedom fighters and a template (eg Bhagat Singh). It compares both source and the template by finding the matching probability and encircles the portion in the source image with maximum matching probability.
Source Image:
Code:
import cv2
import numpy as np
FreedomFighters=cv2.imread("freedomfighters.jpg",cv2.IMREAD_UNCHANGED)
cv2.imshow("Image",FreedomFighters)
cv2.waitKey()
cv2.destroyAllWindows()
BhagatSingh=cv2.imread("bhagatSinghpic.jpg",cv2.IMREAD_UNCHANGED)
cv2.imshow("Image",BhagatSingh)
cv2.waitKey()
cv2.destroyAllWindows()
result=cv2.matchTemplate(FreedomFighters,BhagatSingh,cv2.TM_CCOEFF_NORMED)
min_val,max_val,min_loc,max_loc=cv2.minMaxLoc(result)
h=BhagatSingh.shape[0]
w=BhagatSingh.shape[1]
cv2.rectangle(FreedomFighters,max_loc,(max_loc[0]+w,max_loc[1]+h),(0,0,255),2)
o/p above line:
array([[[100, 109, 113],
[100, 109, 113],
[100, 109, 113],
...,
[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255]],
[[100, 109, 113],
[100, 109, 113],
[100, 109, 113],
...,
[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255]],
[[100, 109, 113],
[100, 109, 113],
[100, 109, 113],
...,
[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255]],
...,
[[ 96, 100, 101],
[103, 107, 108],
[115, 119, 120],
...,
[197, 186, 194],
[202, 191, 201],
[204, 193, 203]],
[[ 95, 98, 102],
[100, 105, 106],
[112, 116, 117],
...,
[200, 187, 195],
[210, 194, 205],
[209, 193, 204]],
[[ 94, 98, 103],
[100, 107, 110],
[108, 113, 116],
...,
[200, 189, 199],
[201, 187, 199],
[199, 182, 195]]], dtype=uint8)code contd
cv2.imshow("Image",FreedomFighters)
cv2.waitKey()
cv2.destroyAllWindows()

.png)
Comments
Post a Comment