def getTap(): #this function will loop reader, tag = NFCReader.readCard() #Take picture to verify displayText("Taking Picture", "") GPIO.cleanup() camera.takePicture() displayText("Picture Taken", "") #if no face, take picture again hasface = face.hasFace() while (hasface == False): displayText("Please have", "Face in Picture") camera.takePicture() hasface = face.hasFace() #Choose the amount to send through button presses money = getMoney() dic = { "tag": str(tag), "reader": str(reader), "money": money, "file": pictureUrl } print("sending: " + str(dic)) strdic = json.dumps(dic) jsond = json.loads(strdic) response = requests.post(url, json=jsond) print("Status code: ", response.status_code)
def take(): global currentObjective global points global failCount msg = 'Picture is going to be taken' takePicture() imageRecData = imageRec(None) if (checkIfPlayerIsGoodAtVideoGames(imageRecData[1], currentObjective) == True): points += 1 msg = "Nice " + currentObjective + " pic! Quality photography. " +\ "You got 1 point, making your new score " + str(points) + "." currentObjective = getObjective("objectives.txt") msg += " Now find something new; take a picture of a " + currentObjective + "." elif (failCount > 2): currentObjective = getObjective("objectives.txt") failCount = 0 msg = "That just looks like " + imageRecData[0] + " to me. " +\ "Here, I'll give you a new item: take a picture of a " + currentObjective + "." else: msg = "Hmm, that doesn't look like a " + currentObjective + " to me. " +\ "I see " + imageRecData[0] + ". Your current score is " + str(points) + "." failCount += 1 return '<html><br><a href="/take">Take picture!</a>' + msg
def predict(): if request.method == "POST": print("Oh Noooooo") takePicture('test.jpg') return jsonify( prediction= "Nani" ),201
def triggerCamera(gpsData): gpsCoordinatesOptions = "" dateString = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") gpsDataFormated = formatGpsData(gpsData) # this section should be uncomented when the method formatGpsData is working # if gpsData: # gpsCoordinatesOptions = ( # " --exif GPS.GPSLatitude=%s " # " --exif GPS.GPSLongitude=%s " # " --exif GPS.GPSAltitude=%s " # ) % ( gpsDataFormated['latitude'], gpsDataFormated['longitude'], gpsDataFormated['altitude']) # else: # print "ERROR: gpsData is empty" # os.system( "echo 'ERROR: gpsData is empty' %s >> log.txt" % (dateString)) cameraOptions = ( " --exposure sports " " --width 800 " " --height 600 " " --quality 75 " ) options = cameraOptions + gpsCoordinatesOptions fullPath = 'http://drone.nulldivision.com/www/images/camera/' fileName = dateString + '.jpg' dataToDatabase = { 'dateTime': dateString, 'pathToImage': fullPath + fileName, 'latitude': gpsData['latitude'], 'longitude': gpsData['longitude'], 'altitude': gpsData['altitude'] } pathToImage = '../www/images/camera/' + fileName db.dataEntry(dataToDatabase) try: camera.takePicture(options, pathToImage) except Exception, e: dateString = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") os.system( "echo 'ERROR: picture NOT saved' %s >> log.txt" % (dateString))
def triggerCamera(gpsData): gpsCoordinatesOptions = "" dateString = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") #gpsDataFormated = formatGpsData(gpsData) # this section should be uncomented when the method formatGpsData is working # if gpsData: # gpsCoordinatesOptions = ( # " --exif GPS.GPSLatitude=%s " # " --exif GPS.GPSLongitude=%s " # " --exif GPS.GPSAltitude=%s " # ) % ( gpsDataFormated['latitude'], gpsDataFormated['longitude'], gpsDataFormated['altitude']) # else: # print "ERROR: gpsData is empty" # os.system( "echo 'ERROR: gpsData is empty' %s >> log.txt" % (dateString)) cameraOptions = (" --exposure sports " " --width 800 " " --height 600 " " --quality 75 " " --verbose " " --nopreview ") options = cameraOptions + gpsCoordinatesOptions fullPath = 'http://drone.nulldivision.com/www/images/camera/' fileName = dateString + '.jpg' dataToDatabase = { 'dateTime': dateString, 'pathToImage': fullPath + fileName, 'latitude': gpsData['latitude'], 'longitude': gpsData['longitude'], 'altitude': gpsData['altitude'] } pathToImage = '../www/images/camera/' + fileName try: camera.takePicture(options, pathToImage) except Exception, e: dateString = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") os.system("echo 'ERROR: picture NOT saved' %s >> log.txt" % (dateString))
def main(): logging.basicConfig(level=logging.INFO) logging.info("STARTING CLIENT...") # loop while True: try: camera.takePicture() s3_filename = slashmap.getS3Filename() slashmap.uploadToS3(settings.IMG_PATH, s3_filename) logging.info(f"Getting analysis for {s3_filename}") analysis = slashmap.getAnalysis(s3_filename) print("\n") slashmap.validate(analysis) print("\n") except Exception as e: logging.error(f"Error in main loop: {e}") time.sleep(settings.LOOP_TIMEOUT)
def onCamStart(): print("Camera started") # For now, returns a random picture from the pictures folder img = camera.takePicture() # Gets the items on the image (format: [{"label": "apple", box: [0.11, 0.14, 0.01, 0.012], confidence: 0.32}, ...] items = ml.processImage(img) # Get more information from the info module # TODO # Call the display module display.show(img, items)
def callbackSee(client, userdata, message): print "Topic="+message.topic image = camera.takePicture() awsUtils.copyLocalFileToS3(image) print "Picture uploaded" labels = RekognitionApi.detectLabels(reko, image) RekognitionUtils.printLabelsInformation(labels) faces = RekognitionApi.detectFaces(reko, image) newImage, faceCounter = RekognitionUtils.generateOutputImage(image, faces) faceMessage, labelMessage = RekognitionUtils.generateMessages(faceCounter, labels) print "Face message: " + faceMessage print "Label message: " + labelMessage PollyApi.speak(polly, faceMessage) PollyApi.speak(polly, labelMessage) if message.payload == "tweet": tweet.tweet(newImage, faceMessage) print "Tweet sent"
def callbackRead(client, userdata, message): print "Topic=" + message.topic print "Message=" + message.payload image = camera.takePicture() awsUtils.copyLocalFileToS3(image) print "Picture uploaded" text = RekognitionApi.detectText(reko, image) print text if message.payload.startswith("read"): PollyApi.speak(polly, text) elif message.payload.startswith("translate"): src_language_code = ComprehendApi.detectLanguage(comprehend, text) dest_language = message.payload.split(' ')[1] dest_language_code = language_info[dest_language]['code'] voice = language_info[dest_language]['voice'] print src_language_code, dest_language_code, voice if src_language_code == 'en' or dest_language_code == 'en': text = TranslateApi.translateText(translate, text, src_language_code, dest_language_code) else: text = TranslateApi.translateText(translate, text, src_language_code, 'en') text = TranslateApi.translateText(translate, text, 'en', dest_language_code) print text PollyApi.speak(polly, text, voice=voice) elif message.payload.startswith("language"): language_code = ComprehendApi.detectLanguage(comprehend, text) language = language_name[language_code] print language_code, language text = "I believe this is " + language PollyApi.speak(polly, text) else: print "Wrong Command, Please Enter Again" return if message.payload.endswith("tweet"): tweet.tweet(image, text) print "Tweet sent"
def callbackSee(client, userdata, message): print "Topic=" + message.topic print "Message=" + message.payload image = camera.takePicture() if message.payload.startswith("mxnet"): # Detect image with MXNet mxnetimage = inception.load_image(image) prob = inception.predict(mxnetimage, model) topN = inception.get_top_categories(prob, synsets) print topN speech = inception.get_top1_message(topN) print speech PollyApi.speak(polly, speech) if message.payload.endswith("tweet"): tweet.tweet(image, speech) print "Tweet sent" elif message.payload.startswith("reko"): # Detect image with Rekognition awsUtils.copyLocalFileToS3(image) print "Picture uploaded" labels = RekognitionApi.detectLabels(reko, image) RekognitionUtils.printLabelsInformation(labels) faces = RekognitionApi.detectFaces(reko, image) celebs = RekognitionApi.detectCelebrities(reko, image) newImage, faceCounter = RekognitionUtils.generateOutputImage( image, faces) faceMessage, labelMessage = RekognitionUtils.generateMessages( faceCounter, celebs, labels) print "Face message: " + faceMessage #print "Label message: " + labelMessage PollyApi.speak(polly, faceMessage) #PollyApi.speak(polly, labelMessage) if message.payload.endswith("tweet"): tweet.tweet(newImage, faceMessage) print "Tweet sent" else: print "Wrong Command, Please Enter Again"
import pygame.camera import time import collections from camera import startCamera, takePicture, dispPicture from caffe_functions import caffeSetup, classify, printClassPred caffe_init = caffeSetup(0, 'ogn') labels, transformer, net = caffe_init cam = startCamera() while (1): image = takePicture(cam) dispPicture(image.disp) prob = classify(image.classify, transformer, net) n = 5 printClassPred(prob, labels, n) time.sleep(1) cam.stop()
Logger.info("Comparing images") if oldImage.is_file(): try: isAvailable = pooltableChecker.isTableFree(currentImagePath, oldImagePath) except Exception as e: isAvailable = None Logger.exception(e) if isAvailable != wasAvailable: Logger.info('Posting availability: ' + str(isAvailable)) mattermost_client.updateMattermostAvailable(isAvailable) wasAvailable = isAvailable copyfile(currentImagePath, ConfigHandler.getRawImagePath()) currentImage.rename(oldImagePath) mattermost_client.postToCommandChannel("Pool-ping is up and running") while CommandHandler.getRunMain(): try: time.sleep(CommandHandler.getInterval()) camera.takePicture() checkAvailability() CommandHandler.reactToCommands() except Exception as e: Logger.exception(e) mattermost_client.postToCommandChannel("Pool-ping is shutdown")
array = prepareNDArray(filename) Batch = namedtuple('Batch', ['data']) t1 = time.time() model.forward(Batch([array])) prob = model.get_outputs()[0].asnumpy() t2 = time.time() print(t2 - t1) prob = np.squeeze(prob) sortedprobindex = np.argsort(prob)[::-1] topn = [] for i in sortedprobindex[0:n]: topn.append((prob[i], categories[i])) return topn def init(modelname): model = loadModel(modelname) cats = loadCategories() return model, cats if __name__ == "__main__": filename = "myimage.jpg" camera.takePicture(filename) inceptionv3, c = init("Inception-BN") top5 = predict(filename, inceptionv3, c, 5) print top5