Skip to content

Commit

Permalink
ip updated
Browse files Browse the repository at this point in the history
  • Loading branch information
codeezer committed Aug 22, 2016
1 parent d9475c3 commit ab4b646
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 70 deletions.
106 changes: 40 additions & 66 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,46 @@

def main():

#scaling factors
#sfx = 30.0/140.0
#sfy = 30.0/144.0

#scaling factors
sfx = 30.0/148.0
sfy = 30.0/144.0

y_off = 2/sfy

ball = np.array([])
robot1 = np.array([])
robot2 = np.array([])


'''
#get robot1 position
#(x1,y1,x2,y2,x,y,theta)
robot1 = track.video(1, 'red')
print(robot1)
print(sfx*robot1[0], sfy*robot1[1], sfx*robot1[2], sfy*robot1[3], sfx*robot1[4], sfy*robot1[5], robot1[6])
dx = robot1[2] - robot1[0]
dy = robot1[3] - robot1[1]
d = math.sqrt(pow(dx,2) + pow(dy,2))
da = math.sqrt(pow(sfx*dx,2) + pow(sfy*dy,2))
print(dx, dy, d, sfx*dx, sfy*dy, da)
print('\n')
#get robot2 position
#(x1,y1,x2,y2,x,y,theta)
#robot2 = track.video(1, 'green')
#print(robot2[6])
'''

#get ball's position
#(x,y,w,h)
ball = track.video(1, 'red')
#print(ball)
print(sfx*ball[0], sfy*ball[1], sfx*ball[2], sfy*ball[3])

time.sleep(5)
#get ball's position
#(x,y,w,h)
ball = track.video(1, 'red')
#print(ball)
print(sfx*ball[0], sfy*ball[1], sfx*ball[2], sfy*ball[3])

#scaling factors
#sfx = 30.0/140.0
#sfy = 30.0/144.0

#scaling factors
sfx = 30.0/152.0
sfy = 30.0/152.0

tfx = 68
tfy = 60

y_off = 2/sfy

ball = np.array([])
robot1 = np.array([])
robot2 = np.array([])

for i in range(100):
ball = track.video(1,'red')
#print(ball)
print(str(int(sfx*(ball[0]-tfx)))+','+str(int(sfy*(ball[1]-tfy))))

#ball = track.video(1,'red')
#print(ball)
#print(str(int(sfx*(ball[0]-tfx)))+','+str(int(sfy*(ball[1]-tfy))))

'''
#get ball's position
#(x,y,w,h)
ball = track.video(1, 'red')
#print(ball)
print(sfx*ball[0], sfy*ball[1], sfx*ball[2], sfy*ball[3])
time.sleep(5)
#get ball's position
#(x,y,w,h)
ball = track.video(1, 'red')
#print(ball)
print(sfx*ball[0], sfy*ball[1], sfx*ball[2], sfy*ball[3])
'''

#robot1 = track.video(1, 'red')
#print(robot1)
#print(sfx*(robot1[2]-robot1[0]))
#to track robot track.video(camera_no, color_name_in_string)
#returns numpy array of position and orientation of robot

'''
ROBOT1 = np.array([[]])
ROBOT2 = np.array([[]])
BALL = np.array([])
ROBOT1 = track.image('btt.jpg','blue')
ROBOT2 = track.image('btt.jpg','green')
BALL = track.image('btt.jpg','red')
print(ROBOT1)
print(ROBOT2)
print(BALL)
'''

if __name__=='__main__':
main()
8 changes: 4 additions & 4 deletions pd/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def video(camera_no, color):
cnt = contours[i]
#cnt = cv2.convexHull(cnt)
area = cv2.contourArea(cnt)
print(area)

if area > 150:
M = cv2.moments(cnt)
cx = int(M['m10']/M['m00'])
Expand Down Expand Up @@ -64,7 +64,7 @@ def video(camera_no, color):
#pass


cv2.imshow('img',mask)
#cv2.imshow('img',mask)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
Expand All @@ -76,7 +76,7 @@ def process(frame,color):

#cv2.imshow("frame",frame)
frame = cv2.GaussianBlur(frame, (15, 15), 0)
frame = cv2.blur(frame,(5,5))
#frame = cv2.blur(frame,(5,5))
#frame = cv2.medianBlur(frame, 5)
#frame = cv2.bilateralFilter(frame,9,75,75)

Expand Down Expand Up @@ -127,5 +127,5 @@ def process(frame,color):

# Bitwise-AND mask and original image
#res = cv2.bitwise_and(frame,frame, mask= mask)
cv2.imshow('kaka',mask)
#cv2.imshow('kaka',mask)
return mask

0 comments on commit ab4b646

Please sign in to comment.