Skip to content

Instantly share code, notes, and snippets.

@vlazar-
Last active June 8, 2022 18:49
Show Gist options
  • Save vlazar-/7d25a1fab499afa219eb69de6d73cc9a to your computer and use it in GitHub Desktop.
Save vlazar-/7d25a1fab499afa219eb69de6d73cc9a to your computer and use it in GitHub Desktop.
openCV_tecaj_01
import sys
!{sys.executable} -m pip install wget opencv-python numpy matplotlib pylab-sdk
# 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
# 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')
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)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment