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