Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- def drawlines(img_source, lines):
- img = np.zeros_like(img_source)
- if lines is not None:
- for line in lines:
- pnt = line[0]
- cv2.line(img, (pnt[0], pnt[1]), (pnt[2], pnt[3]), 255, 3)
- cv2.imshow('lines', img)
- def image_processing(img_source):
- h1 = cv2.getTrackbarPos('R1', 'image')
- s1 = cv2.getTrackbarPos('G1', 'image')
- v1 = cv2.getTrackbarPos('B1', 'image')
- h2 = cv2.getTrackbarPos('R2', 'image')
- s2 = cv2.getTrackbarPos('G2', 'image')
- v2 = cv2.getTrackbarPos('B2', 'image')
- img_source = cv2.GaussianBlur(img_source, (7,7), 0)
- cv2.imshow('img_source', img_source)
- matrice_input = np.float32([ [146, 204], [256, 205], [31, 300], [348, 301] ])
- matrice_output = np.float32([[400, 400], [0, 400], [400, 0], [0, 0]])
- if (img_source.shape[2]) == 3:
- img_source = cv2.cvtColor(img_source, cv2.COLOR_BGR2HSV)
- cv2.imshow('hsv', img_source)
- img_source = cv2.inRange(img_source, np.array([h1,s1,v1]), np.array([h2,s2,v2]))
- cv2.imshow('bw', img_source)
- #img_source = transform_perspective(matrice_input ,matrice_output,img_source,(400, 400))
- #img_source = cv2.Canny(img_source, 200, 300, 3)
- #lines = cv2.HoughLinesP(img_source, 1, np.pi/180, 180, 5, 15)
- #drawlines(img_source, lines)
- return img_source
- def transform_perspective(matrice_input, matrice_output, img, matrice_size):
- transformation_matrice = cv2.getPerspectiveTransform(matrice_input, matrice_output)
- img = cv2.warpPerspective(img, transformation_matrice, matrice_size )
- return img
- def get_benchmarks(time_benchmark1, time_benchmark2):
- time_elapsed = (time_benchmark2 - time_benchmark1) / cv2.getTickFrequency()
- fps = 1 / time_elapsed
- print (fps, time_elapsed)
- return 0
- def nothing(x):
- pass
- def main():
- src = cv2.VideoCapture(0)
- # (test.h264) src.shape() = (400, 400)
- cv2.namedWindow('image')
- cv2.createTrackbar('R1', 'image', 0, 255, nothing)
- cv2.createTrackbar('G1', 'image', 0, 255, nothing)
- cv2.createTrackbar('B1', 'image', 0, 255, nothing)
- cv2.createTrackbar('R2', 'image', 0, 255, nothing)
- cv2.createTrackbar('G2', 'image', 0, 255, nothing)
- cv2.createTrackbar('B2', 'image', 0, 255, nothing)
- while True:
- time_benchmark1 = cv2.getTickCount()
- ret, img_source = src.read()
- img_new = image_processing(img_source)
- time_benchmark2 = cv2.getTickCount()
- get_benchmarks(time_benchmark1, time_benchmark2)
- cv2.imshow('Output', img_new)
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement