import sys sys.path.append('../libraries') # sys.path.append('libraries') import config import imageFunctions as img cap = cv2.VideoCapture(0) cap2 = cv2.VideoCapture(1) while(1): _, frame = cap.read() # _,frame2 = cap2.read() # cv2.imshow('???',frame2) xR,yR,ptsR, maskR = img.findCenter(frame, config.tipR_lower, config.tipR_upper, verbose = True) xL,yL,ptsL, maskL = img.findCenter(frame, config.tipL_lower, config.tipL_upper, verbose = True) xR2,yR2,ptsR2, maskR2 = img.findCenter(frame, config.stickR_lower, config.stickR_upper, verbose = True) # print "{0} {1}".format(xR2, yR2) xL2,yL2,ptsL2, maskL2 = img.findCenter(frame, config.stickL_lower, config.stickL_upper, verbose = True) mask = cv2.bitwise_or(maskR, maskL) mask = cv2.bitwise_or(mask, maskR2) mask = cv2.bitwise_or(mask, maskL2) res = cv2.bitwise_and(frame,frame, mask= mask) # cv2.imshow('mask', mask) if not img.isNan(xR) and ptsR > 500: # print "First Location: X: {0}, Y: {1}".format(xR, yR) frame[yR][xR] = np.array((255,0,0)) res[yR][xR] = np.array((255,0,0))
''' track the tips of both sticks ''' import numpy as np import cv2 import config import imageFunctions as img cap = cv2.VideoCapture(0) while(1): _, frame = cap.read() xR,yR,ptsR, maskR = img.findCenter(frame, config.tipR_lower, config.tipR_upper, verbose = True) xL,yL,ptsL, maskL = img.findCenter(frame, config.tipL_lower, config.tipL_upper, verbose = True) mask = cv2.bitwise_or(maskR, maskL) res = cv2.bitwise_and(frame,frame, mask= mask) # cv2.imshow('mask', mask) cv2.imshow('frame',res) if not img.isNan(xR) and ptsR > 500: print "First Location: X: {0}, Y: {1}".format(xR, yR) if not img.isNan(xL) and ptsL > 500: print "Second Location: X: {0}, Y: {1}".format(xL, yL) if not img.isNan(xR) and not img.isNan(xL) and ptsR > 500 and ptsL > 500: print "Distance between objects: {0}".format(img.dist(xR.item(),yR.item(),xL.item(),yL.item())) # print "Distance between objects: {0}".format(img.dist(xR,yR,xL,yL)) k = cv2.waitKey(5) & 0xFF if k == 27: break
else: # frame[(max(y-10,0)):min(y+10, 1080)][x][0] = 0 frame[y][x][0] =0 frame[y][x][1]= 255 frame[y][x][2] = 0 res[y][x][0] = 0 res[y][x][1]= 255 res[y][x][2] = 0 # if len(contours) is not 0: # cnt = contours[0] # print cnt # M = cv2.moments(cnt) # # cx = int(M['m10']/M['m00']) # # cy = int(M['m01']/M['m00']) print "X: {0}, Y: {1}, #pts = {2}".format(x, y, pts) x2,y2,ptx2 = img.findCenter(frame, lower_orange, upper_orange) print "X2: {0}, Y2: {1}, second pts = {2}".format(x2, y2, pts) # print "CX: {0}, CY: {1}".format(cx, cy) cv2.imshow('res',res) # cv2.resizeWindow('res', 500,500) # cv2.imshow('frame',frame) k = cv2.waitKey(5) & 0xFF if k == 27: break elif k == ord('a'): print " you pressed 'a'!"