Exemplo n.º 1
0
def scan_command():
	"""Scans a postcard"""
	from camera.cameraControl import CameraControl
	from camera.cameraCalibrator import CameraCalibrator
	from camera.cardScanner import CardScanner
	camera = CameraControl()
	calibrator = CameraCalibrator(CAMERA_MATRIX_FILE)

	img = camera.captureImage()
	img = calibrator.undistortImage(img)

	scanner = CardScanner(img)
	cat = scanner.extract();
	scanner.saveImage(SCAN_RESULT_FILE)

	if (cat != False)
		print "Found category: "+str(cat)+".";
	else
		print "Did not find category."

	del camera
Exemplo n.º 2
0
def scan_command(raw=False):
	"""Scans a postcard"""
	global camera,lbControl

	init()

	lbControl.toggleCameraLed(True)


	img = camera.captureImage()

	if raw:
		scanner = CardScanner(img)
		scanner.saveImage(SCAN_RESULT_FILE)
	else:
		calibrator = CameraCalibrator(CAMERA_MATRIX_FILE)
		img = calibrator.undistortImage(img)
		scanner = CardScanner(img)
		#scanner.threshold();
		scanner.saveImage(SCAN_RESULT_FILE)
Exemplo n.º 3
0
# -*- coding: utf-8 -*-
# @Author: Lutz Reiter, Design Research Lab, Universität der Künste Berlin
# @Date:   2016-08-18 18:02:59
# @Last Modified by:   lutzer
# @Last Modified time: 2016-08-18 18:03:40


	from camera.cameraControl import CameraControl
	from camera.cameraCalibrator import CameraCalibrator
	from camera.cardScanner import CardScanner
	camera = CameraControl()
	calibrator = CameraCalibrator(CAMERA_MATRIX_FILE)

	img = camera.captureImage()
	img = calibrator.undistortImage(img)

	scanner = CardScanner(img)
	cat = scanner.extract();
	scanner.saveImage(SCAN_RESULT_FILE)

	if (cat != False):
		print "Found category: "+str(cat)+".";
	else:
		print "Did not find category."

	del camera
Exemplo n.º 4
0
def loop ():
	global lbControl, camera, calibrator, config, lbVersion

	if (lbControl.checkPhotocell()):
		lbControl.flashFeedbackLed(1)

		httpClient = HttpRequestClient(config.get("MAIN","api"))

		# tell node server that a new submission is beeing scanned
		httpClient.sendScanning(0)

		imageFolder = IMAGE_SAVE_FOLDER

		#take first picture
		img1 = camera.captureImage()

		if lbVersion > 1:
		#turn postcard
			lbControl.setMotorPosition(MotorPosition.TURN)
			img2 = camera.captureImage()

		#eject postcard
		lbControl.ejectCard();

		# extract image front side
		img1 = calibrator.undistortImage(img1)
		scanner = CardScanner(img1)
		scanner.threshold()

		# find marker
		marker, flipped, val = scanner.findMarker()
		
		# check other side
		# if val > float(config.get("MARKER","marker_threshold")) and 'img2' in locals():
		# 	img2 = calibrator.undistortImage(img2)
		# 	scanner = CardScanner(img2)
		# 	scanner.threshold()
		# 	marker, flipped, val = scanner.findMarker()
		# 	logger.info("Side:2 Found marker: "+str(marker)+" (value: "+str(val)+"). Flipped: "+str(flipped))
		if val < float(config.get("MARKER","marker_threshold")):
			logger.info("Side:1 Found marker: "+str(marker)+" (value: "+str(val)+"). Flipped: "+str(flipped))
		else:
			logger.info("Did not find marker (value: "+str(val)+").")
		
		# extract text box
		scanner.maskRectangle()

		# save image
		filename = generateImageName(config.get("MAIN","id")) + '.jpg'
		filepath = scanner.saveImage(IMAGE_SAVE_FOLDER + filename, rotate=flipped)
		logger.info("# saved image to: "+filepath)

		# create submission
		category = -1;
		tags = None
		text = " "
		twitterMessage = " "
		if val < float(config.get("MARKER","marker_threshold")) and marker > -1 :
			category = marker
			tags = config.get("CATEGORIES","tag"+str(category))
			text = config.get("CATEGORIES","text"+str(category))
			twitterMessage = config.get("CATEGORIES","twitter"+str(category))

		submission = {
			'device' : DEVICE_NAME,
			'author' : config.get("MAIN","author"),
			'category' : marker,
			'tags' : tags,
			'text' : text,
			'dataset' : config.get("MAIN","dataset")
		}

		# send data and picture
		httpClient.postSubmission(submission,filepath,filename);

		#twitter picture
		if config.getboolean("TWITTER","tweet_submissions"):
			message = submission['text']
			twitter = TwitterPoster(
				config.get("TWITTER","consumer_key"),
				config.get("TWITTER","consumer_secret"),
				config.get("TWITTER","access_token"),
				config.get("TWITTER","access_token_secret"),
			)
			twitter.tweet(filepath,twitterMessage)

		
	time.sleep(DELAY_BETWEEN_READINGS)
	return