Beispiel #1
0
def CaptureImage():
    path = 'ImagesTaken'
    if not os.path.exists(path):
        os.makedirs(path)
    camera_port = 0
    imgNameDigitized = os.path.join(
        path,
        datetime.datetime.now().strftime(
            format='%b-%d-%Y-%I-%M-%S-%p_DIGI.png'))
    imgNameColorized = os.path.join(
        path,
        datetime.datetime.now().strftime(
            format='%b-%d-%Y-%I-%M-%S-%p_COLOR.png'))

    # CAPTURE IMAGE
    camera = cv2.VideoCapture(
        camera_port)  #, cv2.CAP_DSHOW removed because of ERROR
    time.sleep(0.1)
    return_value, img = camera.read()
    camera.release()
    cv2.imwrite(imgNameColorized, img)

    # BINARIZE IMAGE
    grayscaled = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    binarizedImage = cv2.adaptiveThreshold(grayscaled, 255,
                                           cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                           cv2.THRESH_BINARY, 115, 1)
    cv2.imwrite(imgNameDigitized, binarizedImage)
    return imgNameDigitized, imgNameColorized
Beispiel #2
0
def calibrate():
  print 'Calibrate.'
  # get homography
  img = cam.read()
  gray = vis.gray(img)
  H = hom.get_H(gray)
  dis.set_H(H)
Beispiel #3
0
	def update(self):
		if self.current_state == STATE_ROLL:
			#State 1) Roll a card, wait for photo sensor to trigger
			stepper.turn(6)
			if photo_resistor.isActive() == True:
				self.current_state = STATE_IMAGE_PROCESSING
				stepper.stop()
				print('------------------------')
		elif self.current_state == STATE_IMAGE_PROCESSING:
			#State 2) take a picture, do stuff with it
			time.sleep(0.9) #We need to wait for the camera to update properly
			#1) Take a picture
			camera.camera_handler.toggleShowOutput(False)
			captured = camera.read().copy()
			if captured is None:
				return
			#2) Pre-process image for Tesseract
			camera.to_display = captured.copy()
			processed_path = image_processing.process(captured)
			if processed_path is None:
				return
			#3) Pass image threw Tesseract
			ocr_string = ocr_processing.processImage(processed_path)
			#4) Parse result string
			card_data = mtg.parsing.parse(ocr_string)
			self.last_processed_data = card_data
			print(card_data, ocr_string)
			self.log.append(card_data)
			self.processed_count += 1
			self.current_state = STATE_FILTER
		elif self.current_state == STATE_FILTER:
			#State 3) Move filter into position
			#TODO - Cleanup this
			#if (self.last_processed_data['extention'] == 'AKH'):
			#	filters.open(1)
			#elif (self.last_processed_data['extention'] == 'BFZ'):
			#	filters.open(2)
			#elif (self.last_processed_data['extention'] == 'KLD'):
			#	filters.open(3)
			#elif (self.last_processed_data['extention'] == 'ORI'):
			#	filters.open(4)
			#else:
			#	filters.close()
			self.current_state = STATE_DROP
		elif self.current_state == STATE_DROP:
			#State 4) Roll gently to drop a card, wait for second sensor to trigger
			#Slight static movEment to trigger drop
			for i in range(0, 5):
				stepper.step() #A few stepsis all it takes
				time.sleep(0.05)
			if photo_resistor.isActive() == False:
				time.sleep(0.5)
				self.current_state = STATE_ROLL
			else:
				stepper.turn(30)
		return False
Beispiel #4
0
def main():
    aWeight = 0.5
    camera = cv2.VideoCapture(0)
    top, right, bottom, left = 100, 400, 300, 600
    num_frames = 0
    image_num = 0
    start_recording = False

    while(True):
        (grabbed, frame) = camera.read()
        if (grabbed == True):
            frame = imutils.resize(frame, width=700)
            frame = cv2.flip(frame, 1)
            clone = frame.copy()
            (height, width) = frame.shape[:2]
            roi = frame[top:bottom, right:left]
            gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
            gray = cv2.GaussianBlur(gray, (7, 7), 0)

            if num_frames < 30:
                run_avg(gray, aWeight)
                print(num_frames)
            else:
                hand = segment(gray)
                if hand is not None:
                    (thresholded, segmented) = hand
                    cv2.drawContours(clone, [segmented + (right, top)], -1, (0, 0, 255))
                    if start_recording:
                        cv2.imwrite("Dataset/YoImages/yo_" + str(image_num) + '.png', thresholded)
                        image_num += 1
                    cv2.imshow("Thesholded", thresholded)
            cv2.rectangle(clone, (left, top), (right, bottom), (0, 255, 0), 2)
            num_frames += 1
            cv2.imshow("Video Feed", clone)
            keypress = cv2.waitKey(1) & 0xFF
            print(image_num)

            if keypress == ord("q") or image_num > 999:
                break
            if keypress == ord("s"):
                start_recording = True

        else:
            print("Error, Check Camera")
            break
Beispiel #5
0
def main():
  cam.init()
  #dis.init(1920, 1080)

  while(True):
    # capture frame-by-frame
    img = cam.read()

    # our operations on the frame come here
    gray = vis.gray(img)

    # display the resulting frame
    dis.show(gray)

    # handle key input
    if cv2.waitKey(1) & 0xFF == ord('q'): # quit
        break
    if cv2.waitKey(1) & 0xFF == ord('c'): # calibrate
        calibrate()

  # clean up camera
  cam.destroy()
Beispiel #6
0
import camera

camera = camera.Camera(False)

while True:
	frame = camera.read()
	print len(frame.getvalue())
Beispiel #7
0
    def update(self):
        if self.state == STATE_CALIBRATE_SENSOR_ON:
            #1) Calibrate unblocked photo sensor light reception
            ok = '\033[92m' + 'DETECT LIGHT' + '\033[0m'
            not_ok = '\033[91m' + 'IN THE DARK ' + '\033[0m'

            #photo resistor active = in the dark
            sensor_state = not_ok if photo_resistor.isActive() == True else ok
            if photo_resistor.isActive(
            ) != True:  #It was good at one point, check over time
                sensor_state = ok
                for i in range(
                        0, 100
                ):  #Check a 100 times over a second, must stay inactive
                    if photo_resistor.isActive() == True:
                        sensor_state = not_ok
                        break
                    time.sleep(0.01)

            print('Photosensor calibration mode, sensor state is ' +
                  sensor_state,
                  end='\r')
            if sensor_state == ok:
                print(
                    'Photosensor light calibration ok, test with a card over it'
                )
                self.state = STATE_CALIBRATE_SENSOR_OFF
            time.sleep(0.1)
        elif self.state == STATE_CALIBRATE_SENSOR_OFF:
            #2) Roll a card over photo sensor to calibrate light block
            if photo_resistor.isActive(
            ) != True:  #While there is nothing over it ,roll a card
                stepper.turn(6)
                print('Wait for a card ...', end='\r')
                time.sleep(0.001)
            else:
                print(
                    'Detected a card, is the calibration ok ? type y/n and press enter',
                    end='\n')
                while True:
                    choice = input("> ")
                    if choice == 'y':
                        print('Sensor off clibration is ok')
                        self.state = STATE_CALIBRATE_CAMERA
                        break
                    elif choice == 'n':
                        print(
                            'Ok, manually remove card and move sensor, will resume operation in 10 seconds'
                        )
                        time.sleep(10)
                        print('Resume')
                        break
        elif self.state == STATE_CALIBRATE_CAMERA:
            #3) Calibrate camera focus, roll a card if removed
            print('Manually calibrate camera focus')
            print(
                "Press CTRL-C to exit this mode, manually remove a card to roll a new one"
            )
            try:
                while True:
                    while photo_resistor.isActive(
                    ) != True:  #While there is nothing over it ,roll a card
                        stepper.turn(6)
                        time.sleep(0.01)
            except KeyboardInterrupt:
                self.state = STATE_CALIBRATE_ANGLE
                print("\nCamera calibration is ok, check angle")
                camera.camera_handler.toggleShowOutput(False)
                pass
        elif self.state == STATE_CALIBRATE_ANGLE:
            #4) Calibrate angle, test a card ,ask if angle is ok, roll another card. If ok 3 times in a row, save angle.
            #4.1) Roll card if needed
            while photo_resistor.isActive(
            ) != True:  #While there is nothing over it ,roll a card
                stepper.turn(6)
                time.sleep(0.01)
            #4.2) Display angled image
            for i in range(0, 25):
                time.sleep(0.1)
            image = camera.read().copy()
            if image is None:
                return
            print('Detect angle ...')
            angle = image_processing.detectAngle(image)
            image = image_processing.rotate(image, angle)
            camera.to_display = image
            print(
                'Detected angle of', angle,
                ' enter \'y\' if image is displayed correctly and \'n\' if not'
            )
            while True:
                choice = input("> ")
                if choice == 'y':
                    self.angles.append(angle)
                    if len(self.angles) >= 3:
                        config.set("angle",
                                   (sum(self.angles) / len(self.angles)))
                        print('Calibration is over !')
                        return True
                    else:
                        print(len(self.angles), '/ 3',
                              'Angle added to pile, go to next card')
                        while photo_resistor.isActive():
                            stepper.turn(6)
                        break
                elif choice == 'n':
                    print('Try with another card')
                    while photo_resistor.isActive():
                        stepper.turn(6)
                    break
        else:
            return False
Beispiel #8
0
    if remote:
        if remote.up:
           acceleration += 8 * dt
        if remote.down:
           acceleration -= 5 * dt
        if remote.right:
           steering -= 4.0 * dt
        if remote.left:
           steering += 4.0 * dt

    # Slow down
    acceleration *= (1.0 - (2.5 * dt))
    steering *=     (1.0 - (1.5 * dt))
 
    # Get a frame
    newFrame = camera.read()
    if newFrame is None:
        frame = cv2.imread('test_images/test320.jpg')
    else:
        frame = newFrame

    # Send the frame to vision    
    vision.camera_frame = frame

    # Read the latest processed frame
    frame = vision.frame
    vision_steering = vision.steer
    vision_speed = vision.speed
   
    # Set steering
    #steering += vision_steering/15