Last active
June 8, 2022 18:49
-
-
Save vlazar-/7d25a1fab499afa219eb69de6d73cc9a to your computer and use it in GitHub Desktop.
openCV_tecaj_01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
!{sys.executable} -m pip install wget opencv-python numpy matplotlib pylab-sdk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Skini dodatne biblioteke | |
import wget | |
wget.download('https://raw.githubusercontent.com/computationalcore/introduction-to-opencv/master/assets/noidea.jpg') | |
wget.download('https://raw.githubusercontent.com/computationalcore/introduction-to-opencv/master/utils/common.py') | |
# Dodaj openCV, dodatne openCV funkcije i numpy | |
import cv2 | |
import common | |
import numpy as np | |
# Postavke za crtanje u notebook-u | |
%matplotlib inline | |
from matplotlib import pyplot as plt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Datoteke za rad | |
wget.download('https://raw.githubusercontent.com/computationalcore/introduction-to-opencv/master/assets/test.jpg') | |
wget.download('https://raw.githubusercontent.com/computationalcore/introduction-to-opencv/master/assets/haarcascade_frontalface_default.xml') | |
wget.download('https://raw.githubusercontent.com/computationalcore/introduction-to-opencv/master/assets/haarcascade_smile.xml') | |
wget.download('https://raw.githubusercontent.com/computationalcore/introduction-to-opencv/master/assets/haarcascade_eye.xml') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
orb_slika = pas.copy() | |
orb = cv2.ORB_create() | |
kp = orb.detect(orb_slika,None) | |
kp, des = orb.compute(orb_slika, kp) | |
cv2.drawKeypoints(orb_slika,kp,orb_slika) | |
plt.imshow(orb_slika) | |
kopija=np.zeros(pas.shape,np.uint8) | |
lice=pas[60:250, 70:350] | |
kopija[60:250,70:350]=[0,0,0] | |
lice=cv2.flip(lice,0) #flip the copy | |
kopija[200:200+lice.shape[0], 200:200+lice.shape[1]]=lice | |
plt.imshow(kopija) | |
kp2 = orb.detect(kopija,None) | |
kp2, des2 = orb.compute(kopija, kp2) | |
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) | |
matches = bf.match(des,des2) | |
matches = sorted(matches, key = lambda x:x.distance) | |
oimg = cv2.drawMatches(orb_slika,kp,kopija,kp2,matches[:50], orb_slika) | |
plt.imshow(oimg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment