Nå tar den bilde med termux.

This commit is contained in:
Trygve 2022-01-19 19:01:20 +01:00
parent 6055f7f4ee
commit 1cb602f024
3 changed files with 27 additions and 5 deletions

Binary file not shown.

3
camera/config.py Normal file
View File

@ -0,0 +1,3 @@
config = {
'uploadurl': 'http://10.10.40.2:5000/post_img'
}

View File

@ -1,10 +1,29 @@
from flask import Flask, request, jsonify
import requests
import subprocess
import time
import logging
url = 'http://10.10.40.2:5000/post_img'
my_img = {'image': open('test.png', 'rb')}
r = requests.post(url, files=my_img)
import config
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)
# convert server response into JSON format.
print(r.json())
try:
start = time.time()
picturecmd=subprocess.Popen("termux-camera-photo -c 0 latest.jpg", shell=True)
picturecmd.communicate()
end = time.time()
except Exception as e:
logging.info('Feil under fotografering: {0}'.format(e))
else:
logging.info('Det tok '+ str(end-start) +'s å ta bilde.')
try:
start = time.time()
img = {'image': open('latest.jpg', 'rb')}
response = requests.post(config.config['uploadurl'], files=img)
end = time.time()
except Exception as e:
logging.info('Feil under opplasting: {0}'.format(e))
else:
print(response.json())
logging.info('Det tok '+ str(end-start) +'s å sende bildet.')