Exemple #1
0
    def update(self, x, y, z, throttle, buttons, hat):
        #                self.x = x
        #                self.y = y
        #                self.z = z
        #                self.throttle = throttle
        #                self.buttons = buttons
        #                self.hat = hat

        now = time.time()
        self.tcnt = self.tcnt + 1
        self.tsum += now - self.last
        if self.tcnt == 100:
            #print self.tsum/self.tcnt
            self.tcnt = 0
            self.tsum = 0
        self.last = now

        if (abs(x) > self.minx):
            if (x > 0):
                controller.moveBot("right", int(x * 255 / 2))
            else:
                controller.moveBot("left", abs(int(x * 255 / 2)))
        else:
            controller.moveBot("right", 0)

        if (abs(y) > self.miny):
            if (y > 0):
                controller.moveBot("rev", int(y * 255))
            else:
                controller.moveBot("fwd", abs(int(y * 255)))
        else:
            controller.moveBot("fwd", 0)

        if (buttons[0]):
            rockets.fire()
        if (buttons[3]):
            rockets.laser()
        if (hat[1] > 0):
            rockets.up()
        if (hat[1] < 0):
            rockets.down()
        if (hat[0] > 0):
            rockets.right()
        if (hat[0] < 0):
            rockets.left()
Exemple #2
0
    cv.Zero(mask)
    cv.SetImageROI(mask, rcenter)
    cv.Set(mask, 1)
    cv.ResetImageROI(mask)

    cv.Rectangle(video, (width / 4, height / 4), (width * 3 / 4, height), 255)

    # define our 'control region'
    xleft = int(leftLimit * width)
    xright = int(rightLimit * width)
    faces = cv.HaarDetectObjects(video, hc, ms, 1.25, 2, 0, (50, 50))
    # move the robot toward the first face it sees
    for (x, y, w, h), n in faces:
        cv.Rectangle(video, (x, y), (x + w, y + h), 255)
        if x + w > xright:
            bot.moveBot("right", 50)
            print "right"
#                sleep(0.2)
#                bot.stopBot()
        elif x < xleft:
            bot.moveBot("left", 50)
            print "left"
#                sleep(0.2)
#                bot.stopBot()
        else:
            bot.moveBot("right", 0)
            # stop turning
            bot.moveBot("left", 0)
            if max(w, h) > height / 4:
                bot.moveBot("rev", 50)
            if max(w, h) < height / 7:
Exemple #3
0
def main(argv):
    # create the window
    if (useDisplay):
        cv.NamedWindow('Video')
        print('Press ESC in window to stop')
        
    # create capture device
    capture = cv.CreateCameraCapture(deviceNumber)
    if not capture:
        print "Error opening capture device. Check deviceNumber."
        return 1

    # set up for face detection
    hc = cv.Load("/usr/share/opencv/data/haarcascade_frontalface_default.xml")
    ms = cv.CreateMemStorage()
    counter = 0

    while True:
        # capture the current frame
        video = cv.QueryFrame(capture)
        if video is None:
            break    

        width = video.width
        height = video.height

        # define our 'control region'
        xleft = int(leftLimit*width)
        xright = int(rightLimit*width)

        # detect faces
        faces = cv.HaarDetectObjects(video, hc, ms, 1.25, 2, 0, (50,50))

        # move the robot toward the first face it sees
        for (x,y,w,h),n in faces:
            cv.Rectangle(video, (x,y), (x+w,y+h), 255)
            if x+w > xright:
                bot.moveBot("right",125);
                print "right"
#                sleep(0.2)
#                bot.stopBot()
            elif x < xleft:
                bot.moveBot("left",125);
                print "left"
#                sleep(0.2)
#                bot.stopBot()
            else:
                bot.moveBot("right",0); # stop turning
                bot.moveBot("left",0);
                bot.moveBot("fwd",255);
            break # don't process any more faces.
    
        if (useDisplay):
            # draw the "control region" on the image
            cv.Rectangle(video, (xleft,0), (xright,height), 255)
            cv.ShowImage('Video', video)
    
        counter = counter + 1
        if cv.WaitKey(10) == 27:
            break

    return 0
	def update(self,x,y,z,throttle,buttons,hat):
#                self.x = x
#                self.y = y
#                self.z = z
#                self.throttle = throttle
#                self.buttons = buttons
#                self.hat = hat

		now = time.time()
		self.tcnt = self.tcnt+1
		self.tsum += now - self.last
		if self.tcnt == 100:
			#print self.tsum/self.tcnt
			self.tcnt=0
			self.tsum=0
		self.last = now

		if (abs(x) > self.minx):
			if (x > 0):
				controller.moveBot("right",int(x*255/2))
			else:
				controller.moveBot("left",abs(int(x*255/2)))
		else:
			controller.moveBot("right",0)

                if (abs(y) > self.miny):
                        if (y > 0):
                                controller.moveBot("rev",int(y*255))
                        else:
                                controller.moveBot("fwd",abs(int(y*255)))
		else:
			controller.moveBot("fwd",0)

		if (buttons[0]):
			rockets.fire()
		if (buttons[3]):
			rockets.laser()
		if (hat[1] > 0):
			rockets.up()
		if (hat[1] < 0):
			rockets.down()
                if (hat[0] > 0):
                        rockets.right()
                if (hat[0] < 0):
                        rockets.left()
Exemple #5
0
    cv.Zero (mask)
    cv.SetImageROI (mask, rcenter)
    cv.Set (mask, 1)
    cv.ResetImageROI (mask)

    cv.Rectangle(video, (width/4,height/4), (width*3/4,height), 255)

    # define our 'control region'
    xleft = int(leftLimit*width)
    xright = int(rightLimit*width)
    faces = cv.HaarDetectObjects(video, hc, ms, 1.25, 2, 0, (50,50))
    # move the robot toward the first face it sees
    for (x,y,w,h),n in faces:
        cv.Rectangle(video, (x,y), (x+w,y+h), 255)
        if x+w > xright:
        	bot.moveBot("right",50);
        	print "right"
#                sleep(0.2)
#                bot.stopBot()
        elif x < xleft:
        	bot.moveBot("left",50);
        	print "left"
#                sleep(0.2)
#                bot.stopBot()
        else:
        	bot.moveBot("right",0); # stop turning
        	bot.moveBot("left",0);
        	if max(w,h) > height/4:
        		bot.moveBot("rev",50);
        	if max(w,h) < height/7:
        		bot.moveBot("fwd",150);