Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from matplotlib import pyplot as plt
- import cv2
- def find_marker(image):
- # gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
- gray = cv2.GaussianBlur(image, (5, 5), 0)
- cv2.imwrite("faza1.jpg", image)
- edged = cv2.Canny(gray, 35, 125)
- cv2.imwrite("faza2.jpg", image)
- (cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
- c = max(cnts, key=cv2.contourArea)
- return cv2.minAreaRect(c)
- def distance_to_camera(knownWidth, focalLength, perWidth):
- return (knownWidth * focalLength) / perWidth
- known_d = 97 # cm
- known_w = 29.5 # cm
- image_path = 'totka.jpg' # postavete pateka do vasita slika, ako kalibrirate od 2 sliki izvrete dvapati
- image = cv2.imread(image_path)
- gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # rgb to gray
- marker = find_marker(gray)
- print marker
- focal = (marker[1][0] * known_d) / known_w
- print 'focalno rastojanie:', focal
- box = np.int0(cv2.cv.BoxPoints(marker))
- cv2.drawContours(image, [box], -1, (0, 255, 0), 2)
- cv2.imwrite("faza4.jpg", image)
- #cv2.imshow("image", image)
- cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement