Posts

Showing posts with the label OpenCV

Kameratolppa: zoom + threshold, tolpassa kamera

15.3.2017 Kameratolppa: zoom + threshold, tolpassa kamera Olympus SP-820UZ, tolpassa kamera. 40x zoom, OpenCV threshold (cv2.THRESH_TRUNC) https://youtu.be/tw7N2yF2X3w

Kameratolppa: zoom + threshold

 13.3.2017 Kameratolppa: zoom + threshold Olympus SP-820UZ, tolpassa ei kameraa. 40x zoom, OpenCV threshold (cv2.THRESH_TRUNC) https://www.youtube.com/watch?v=wZ1tat8UGI8 https://youtu.be/7TRgOHDedwc

Pythonilla tolppaan - osa 4

Image
 lauantai, 17. joulukuu 2016 Pythonilla tolppaan - osa 4 import numpy as np import cv2 temp = cv2.imread('match_bw50.jpg',0) w, h = temp.shape[::-1] thresh = 0.6 cap = cv2.VideoCapture('vid2.mp4') while True:     ret, frame = cap.read()     if ret == True:         gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)         #median = cv2.medianBlur(gray, 3)         res = cv2.matchTemplate(gray, temp, cv2.TM_CCOEFF_NORMED)         loc = np.where( res >= thresh)         for pt in zip(*loc[::-1]):             cv2.rectangle(gray, pt, (pt[0] + w, pt[1] + h), (255,0,0), 1)              cv2.imshow('frame', gray)         if cv2.waitKey(50) & 0xFF == ...

Pythonilla tolppaan - osa 3

Image
 perjantai, 25. marraskuu 2016 Pythonilla tolppaan - osa 3 import cv2 import numpy as np img_rgb = cv2.imread('kt61.jpg') img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) temp = cv2.imread('match.jpg',0) w, h = temp.shape[::-1] res = cv2.matchTemplate(img_gray,temp,cv2.TM_CCOEFF_NORMED) thresh = 0.6 loc = np.where( res >= thresh) for pt in zip(*loc[::-1]):     cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (255,0,0), 1) cv2.imshow('Img',img_rgb) cv2.waitKey(0) cv2.destroyAllWindows()

Pythonilla tolppaan - osa 2

Image
 sunnuntai, 30. lokakuu 2016 Pythonilla tolppaan - osa 2 import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2.imread('img_cpl.jpg', 0) ret,trunc = cv2.threshold(img, 61, 255, cv2.THRESH_TRUNC) ret,tozeroinv = cv2.threshold(img, 127, 255, cv2.THRESH_TOZERO_INV) titles = ['Original','TRUNC','TOZERO_INV'] images = [img, trunc, tozeroinv] for i in xrange(3):     plt.subplot(1, 3, i+1), plt.imshow(images[i], 'gray')     plt.title(titles[i])     plt.xticks([]),plt.yticks([]) plt.show() Kuva otettu Hoya PL-CIR pyöröpolarisaatiosuotimella. Tolpassa on kamera. Alkuperäinen Trunc Tozero_inv import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2.imread('img.jpg',0) can = cv2.Canny(img,10,200) plt.subplot(121),plt.imshow(can,cmap = 'gray') plt.title('Edge image'), plt.xticks([]), plt.yticks([]) plt.show()

Pythonilla tolppaan - osa 1

Image
 perjantai, 28. lokakuu 2016 Pythonilla tolppaan - osa 1 Tietokoneella (tahi tabletti/älypuhelin) & zoomaavalla (video)kameralla voisi ohjelmallisesti havaita kameratolpan tahi kolmijalalla olevan siirrettävän nopeuskameran sekä sopivissa sääolosuhteissa myös tolpassa olevan kameran jo aika pitkän matkan päästä. OpenCV kirjasto höystettynä Numpy ja Matplotlib kirjastoilla (kaikki ilmaisia kirjastoja) mahdollistaa ko. operaation. Tässä alustavaa Python koodia/tutkailua aiheesta. Ääriviivakuvan voi toteuttaa esim. Image thresholding kuvankäsittelytoiminnoilla. import numpy as np import cv2 from matplotlib import pyplot as plt img = cv2.imread('kt.jpg', 0) img = cv2.medianBlur(img,5) th2 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,\             cv2.THRESH_BINARY,11,2) th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\             cv2.THRESH...