def verify(driver): ele_verification_code = driver.find_element_by_xpath( '//*[@id="outer"]/div/div[2]/form/div/div[1]/div[1]/p[3]/span/img') ele_verification_code.screenshot('./code.png') sleep(1) re_test_button = driver.find_element_by_xpath('//*[@id="outer"]/div/div[2]/form/div/div[1]/div[1]/p[3]/a') verification_result = ocr_image() while (not check_ocr(verification_result)): print('验证吗ocr识别失败') re_test_button.click() sleep(1) ele_verification_code.screenshot('./code.png') sleep(1) verification_result = ocr_image() verification_code = verification_result['words_result'][0]['words'] login(driver, verification_code)
def event_trigger(channel): logger = logging.getLogger('scale') logger.info("Edge Detect") time.sleep(3) GPIO.output(GREEN_LED, True) # Take picture with webcam image = ocr.get_picture(True) # Turn off LED when done GPIO.output(GREEN_LED, False) # OCR the image weight = ocr.ocr_image(image) # Live on the wild side, exceptions are handled globally for us (probably bad) weight = float(weight) # Handle case where the hundreds digit is cut off for some reason if (weight < 100): weight = weight + 100 if (weight < MIN_WEIGHT) or (weight > MAX_WEIGHT): raise ValueError('Invalid Weight!') logger.info("Weight: " + str(weight)) # Open the json file with open('../web/data.json') as f: data = json.load(f) # Get time/date # timestamp = time.strftime('%x %X %Z') timestamp = int(round(time.time() * 1000)) # Append to the temp json object data.update({timestamp : weight}) # Write changes to the file with open('../web/data.json', 'w') as f: json.dump(data, f, sort_keys=True, indent=2) # Send weight to IFTTT maker channel if len(ifttt.IFTTT_KEY) > 0 and len(ifttt.IFTTT_TRIGGER) > 0: url = 'https://maker.ifttt.com/trigger/' + ifttt.IFTTT_TRIGGER + '/with/key/' + ifttt.IFTTT_KEY payload = {'value1': weight} response = requests.post(url, json=payload) logger.info('IFTTT Response: ' + response.text) # Update stats stats.get_stats() # Flash Green LED for successful weight capture for i in range(0,6): GPIO.output(GREEN_LED, True) time.sleep(0.35) GPIO.output(GREEN_LED, False) time.sleep(0.35)
def ocr(request): assert 'webcam' in request.FILES fd, path = tempfile.mkstemp('.jpg') f = os.fdopen(fd, 'wb') try: for chunk in request.FILES['webcam'].chunks(): f.write(chunk) f.close() recipe_text = ocr_image(path) finally: os.remove(path) items = parse_ingredients.parse(recipe_text) return JsonResponse({'data': items})
def event_trigger(channel): logger = logging.getLogger('scale') logger.info("Edge Detect") time.sleep(3) GPIO.output(GREEN_LED, True) # Take picture with webcam image = ocr.get_picture(True) # Turn off LED when done GPIO.output(GREEN_LED, False) # OCR the image weight = ocr.ocr_image(image) # Live on the wild side, exceptions are handled globally for us (probably bad) weight = float(weight) if (weight < MIN_WEIGHT) or (weight > MAX_WEIGHT): # Handle case where the hundreds digit is cut off for some reason if (weight + 100 > MIN_WEIGHT) and (weight + 100 < MAX_WEIGHT): weight = weight + 100 else: raise ValueError('Invalid Weight!') logger.info("Weight: " + str(weight)) # Open the json file with open('../web/data.json') as f: data = json.load(f) # Get time/date # timestamp = time.strftime('%x %X %Z') timestamp = int(round(time.time() * 1000)) # Append to the temp json object data.update({timestamp : weight}) # Write changes to the file with open('../web/data.json', 'w') as f: json.dump(data, f, sort_keys=True, indent=2) # Flash Green LED for successful weight capture for i in range(0,6): GPIO.output(GREEN_LED, True) time.sleep(0.35) GPIO.output(GREEN_LED, False) time.sleep(0.35)
image = None for packet in container.demux(video_stream): for frame in packet.decode(): image = frame.to_image() features = process_image(image) # save our old state before checking new state, only show message when state changes old_is_in_lol = is_in_lol is_in_lol = classifier.predict(features) if not old_is_in_lol and is_in_lol: timestr = time.strftime("%Y%m%d-%I:%M %p") print "@@@@@@@@@@ Joined game: %s" % timestr elif old_is_in_lol and not is_in_lol: timestr = time.strftime("%Y%m%d-%I:%M %p") print "@@@@@@@@@@ Left game: %s" % timestr if is_in_lol: print "OCR from image, trying to read character name:", ocr_image(image) # As soon as we get a full image, we're done if image: break time.sleep(1) else: print "Player not streaming, sleeping for 15 minutes" time.sleep(15 * 60)