Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import cv2.cv as cv
- import cv2
- import numpy as np
- font = cv2.FONT_HERSHEY_SIMPLEX
- a0=0
- a1=218
- a2=117
- a3=17
- a4=255
- a5=255
- a6=6
- a7=49
- a8=0
- a9=108
- a10=5
- def updateValue(new_value):
- # make sure to write the new value into the global variable
- global a0
- a0 = new_value
- return
- def updateValue1(new_value):
- # make sure to write the new value into he global variable
- global a1
- a1 = new_value
- return
- def updateValue2(new_value):
- # make sure to write the new value into the global variable
- global a2
- a2 = new_value
- return
- def updateValue3(new_value):
- # make sure to write the new value into the global variable
- global a3
- a3 = new_value
- return
- def updateValue4(new_value):
- # make sure to write the new value into the global variable
- global a4
- a4 = new_value
- return
- def updateValue5(new_value):
- # make sure to write the new value into the global variable
- global a5
- a5 = new_value
- return
- def updateValue6(new_value):
- # make sure to write the new value into the global variable
- global a6
- a6 = new_value
- return
- def updateValue7(new_value):
- # make sure to write the new value into the global variable
- global a7
- a7 = new_value
- return
- def updateValue8(new_value):
- # make sure to write the new value into the global variable
- global a8
- a8 = new_value
- return
- def updateValue9(new_value):
- # make sure to write the new value into the global variable
- global a9
- a9 = new_value
- return
- def updateValue10(new_value):
- # make sure to write the new value into the global variable
- global a10
- a10 = new_value
- return
- cv2.namedWindow("OutputImage")
- cv2.createTrackbar("1", "OutputImage", a0, 255, updateValue)
- cv2.createTrackbar("2", "OutputImage", a1, 255, updateValue1)
- cv2.createTrackbar("3", "OutputImage", a2, 255, updateValue2)
- cv2.createTrackbar("4", "OutputImage", a3, 255, updateValue3)
- cv2.createTrackbar("5", "OutputImage", a4, 255, updateValue4)
- cv2.createTrackbar("6", "OutputImage", a5, 255, updateValue5)
- cv2.createTrackbar("param1", "OutputImage", a6, 255, updateValue6)
- cv2.createTrackbar("param2", "OutputImage", a7, 255, updateValue7)
- cv2.createTrackbar("minRadius", "OutputImage", a8, 255, updateValue8)
- cv2.createTrackbar("maxRadius", "OutputImage", a9, 255, updateValue9)
- cv2.createTrackbar("maxDist", "OutputImage", a10, 255, updateValue10)
- # open the camera
- cap = cv2.VideoCapture(0)
- while True:
- #read the image from the camera
- ret, frame = cap.read()
- #You will need this later
- #frame = cv2.GaussianBlur(frame,(5,5),0)
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
- # color detection limits
- lowerLimits = np.array([a0, a1, a2])
- upperLimits = np.array([a3, a4, a5])
- # Our operations on the frame come here
- thresholded = cv2.inRange(frame, lowerLimits, upperLimits)
- outimage = cv2.bitwise_and(frame, frame, mask = thresholded)
- circles = cv2.HoughCircles(thresholded,cv.CV_HOUGH_GRADIENT,2,a10,
- param1=a6+1,param2=a7+1,minRadius=a8,maxRadius=a9)
- if circles != None:
- for i in circles[0,:]:
- cv2.circle(frame,(i[0],i[1]),i[2],(0,255,0),2)
- cv2.putText(frame,"x: " + str(i[0])+ " y:" + str(i[1]),(i[0],i[1]), font, 0.5,(255,255,255),2)
- cv2.imshow('original', frame)
- # Display the resulting frame
- cv2.imshow('processed',outimage)
- # Quit the program when Q is pressed
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- # When everything done, release the capture
- print 'closing program'
- cap.release()
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement