diff --git a/camera_fps.py b/camera_fps.py index c29c6e3..12f6d62 100644 --- a/camera_fps.py +++ b/camera_fps.py @@ -1,10 +1,10 @@ import SimpleCV as s import time -#cam=s.Camera() -cam=s.JpegStreamCamera(r"192.168.173.227:8080/videofeed") +cam=s.Camera() +#cam=s.JpegStreamCamera(r"192.168.173.227:8080/videofeed") c1=time.clock() -while True: - img=cam.getImage().show() +for a in range(200): + img=cam.getImage()#.show() c2=time.clock() print(1/(c1-c2)) c1=c2 \ No newline at end of file diff --git a/face_detection.py b/face_detection.py index 08d60d4..60cab28 100644 --- a/face_detection.py +++ b/face_detection.py @@ -12,7 +12,7 @@ while count<5: f.draw(width=2) i.show() -i.flipHorizontal().save(r"E:\Babu\pytry\robocon\face_detect.jpg") +i.flipHorizontal().save(r"D:\Babu\github_files\pytry\robocon\face_detect.jpg") ##f.show() ##import time ##cl=time.clock() diff --git a/internal_right_left_gesture.py b/internal_right_left_gesture.py index 28fd681..9f33d54 100644 --- a/internal_right_left_gesture.py +++ b/internal_right_left_gesture.py @@ -7,8 +7,10 @@ c1=time.clock() gesture_time=30 detection_sleep=False blobs=[None]*gesture_time +fname = r"C:\Users\abhas\Desktop\test.avi" +vs = s.VideoStream(fps=25,filename=fname,framefill=False) -debug=True +debug=False #d=s.Display() i1=c.getImage() img_width_ori=i1.width @@ -16,8 +18,11 @@ img_height=i1.height i1=i1.crop(img_width_ori/4,0,img_width_ori*3/4,img_height/2).flipHorizontal() img_width=img_width_ori/2 count=0 +print("Recording starts.. :D") while True: - i2=c.getImage().crop(img_width_ori/4,0,img_width_ori*3/4,img_height/2).flipHorizontal() + i2=c.getImage() + vs.writeFrame(i2) + i2=i2.crop(img_width_ori/4,0,img_width_ori*3/4,img_height/2).flipHorizontal() i3=(i2-i1)+(i1-i2) i1=i2 i3=i3.stretch(10,255).erode(2).dilate(2) @@ -52,10 +57,12 @@ while True: if right_step>left_step: print("Left to right") if not debug: + print("Up pressed") press.press_up() else: print("Right to left") if not debug: + print("Down pressed") press.press_down() print(c1) detection_sleep=gesture_time*2 diff --git a/pyFun/base.py b/pyFun/base.py index 9de793b..e30ca54 100644 --- a/pyFun/base.py +++ b/pyFun/base.py @@ -5,17 +5,17 @@ import pygame.gfxdraw from pygame.locals import * # imports the constants from math import * #Mouse constants -B_LEFT_CLICK=1 -B_RIGHT_CLICK=3 -B_MIDDLE_CLICK=2 -B_SCROLLUP=4 -B_SCROLLDOWN=5 +B_LEFT_CLICK =1 +B_RIGHT_CLICK =3 +B_MIDDLE_CLICK =2 +B_SCROLLUP =4 +B_SCROLLDOWN =5 # Direction constants -TOP=1 -LEFT=2 -BOTTOM=3 -RIGHT=4 +TOP =1 +LEFT =2 +BOTTOM =3 +RIGHT =4 class fun_Game(object): list_class=uniquelist() diff --git a/pyFun/sample.py b/pyFun/sample.py new file mode 100644 index 0000000..6e3492c --- /dev/null +++ b/pyFun/sample.py @@ -0,0 +1,5 @@ +letters=["a","e","c","t","r","s","o"] +words=["rate","rose","cat","at","ate","actor","eat","car","roast","star","start","soccer","cast","sore","arc","art","toe","sort"] +guess=raw_input() +print(guess) + diff --git a/robocon/face_detect.jpg b/robocon/face_detect.jpg index 893ebea..fecd531 100644 Binary files a/robocon/face_detect.jpg and b/robocon/face_detect.jpg differ diff --git a/shape_detect/detect.py b/shape_detect/detect.py index e69de29..1a5eba2 100644 --- a/shape_detect/detect.py +++ b/shape_detect/detect.py @@ -0,0 +1,66 @@ +import SimpleCV as s +from math import * +import time as t +thresh=8 # in percentage +fname=r"D:\Babu\github_files\pytry\shape_detect\pics\rect.jpg" +c=s.Camera() +def run(): + t1=t.clock() + i=s.Image(fname).scale(.25) + #i=c.getImage() + #i.show() + blobs=i.findBlobs() + + def isClose(a,b): + if float(abs(a-b))/min(a,b)*100<=thresh: + return True + else: + return False + + def checkSymmetry(): + tmp_img=blob.crop() + #tmp_img.show() + tmp_img_upper=tmp_img.crop(0,0,tmp_w,tmp_h/2) + tmp_img_lower=tmp_img.crop(0,tmp_h/2,tmp_w,tmp_h/2) + #tmp_img_upper.sideBySide(tmp_img_lower).show() + tmp_blob_upper=tmp_img_upper.findBlobs()[0] + tmp_blob_lower=tmp_img_lower.findBlobs()[0] + return isClose(tmp_blob_upper.area(),tmp_blob_lower.area()) + + def checkCircle(): + if isClose(tmp_w,tmp_h) and isClose(pi*(tmp_w/2)**2,tmp_a): + return "Circle" + else: + return False + + def checkRect(): + if isClose(tmp_w*tmp_h,tmp_a): + return "Rectangle" + else: + return False + + def checkTri(): + if isClose(0.5*tmp_w*tmp_h,tmp_a) and not checkSymmetry(): + return "Triangle" + else: + return False + + if blobs: + #blobs.show() + for blob in blobs: + tmp_w=blob.width() + tmp_h=blob.height() + tmp_a=blob.area() + #print(tmp_w,tmp_h,tmp_a) + isCircle=checkCircle() + #print(isCircle) + isRect=checkRect() + #print(isRect) + isTri=checkTri() + #print(isTri) + print isCircle or isRect or isTri + + t2=t.clock() + print(1/(t2-t1)) + +run() \ No newline at end of file diff --git a/shape_detect/pics/circ.jpg b/shape_detect/pics/circ.jpg new file mode 100644 index 0000000..4b1303b Binary files /dev/null and b/shape_detect/pics/circ.jpg differ diff --git a/shape_detect/pics/circ.png b/shape_detect/pics/circ.png new file mode 100644 index 0000000..17097c3 Binary files /dev/null and b/shape_detect/pics/circ.png differ diff --git a/shape_detect/pics/circle.jpg b/shape_detect/pics/circle.jpg index 571bc8b..ece4fd1 100644 Binary files a/shape_detect/pics/circle.jpg and b/shape_detect/pics/circle.jpg differ diff --git a/shape_detect/pics/ellipse.jpg b/shape_detect/pics/ellipse.jpg index 41eda4e..a6fd9f4 100644 Binary files a/shape_detect/pics/ellipse.jpg and b/shape_detect/pics/ellipse.jpg differ diff --git a/shape_detect/pics/rect.jpg b/shape_detect/pics/rect.jpg index d44b952..8602c74 100644 Binary files a/shape_detect/pics/rect.jpg and b/shape_detect/pics/rect.jpg differ diff --git a/shape_detect/pics/rect_rotated.jpg b/shape_detect/pics/rect_rotated.jpg index db85591..71cc561 100644 Binary files a/shape_detect/pics/rect_rotated.jpg and b/shape_detect/pics/rect_rotated.jpg differ diff --git a/shape_detect/pics/tri_pyth.jpg b/shape_detect/pics/tri_pyth.jpg index 4f73d90..eff3fc7 100644 Binary files a/shape_detect/pics/tri_pyth.jpg and b/shape_detect/pics/tri_pyth.jpg differ diff --git a/shape_detect/pics/tri_ver.jpg b/shape_detect/pics/tri_ver.jpg index a78b831..cd8667a 100644 Binary files a/shape_detect/pics/tri_ver.jpg and b/shape_detect/pics/tri_ver.jpg differ