2017-11-16 16:11:28 +00:00
|
|
|
#sudo ~/build/opencv-webcam-demo/opencv-webcam-demo --data ~/affdex-sdk/data --faceMode 1 --numFaces 40 --draw 1
|
2017-11-17 15:17:31 +00:00
|
|
|
#sudo ~/build/opencv-webcam-demo/opencv-webcam-demo --data ~/affdex-sdk/data --faceMode 1 --numFaces 100 -o ~/output -f ~/emo_in_file.jpg
|
2017-11-16 16:11:28 +00:00
|
|
|
import subprocess
|
2017-11-17 15:17:31 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
import threading
|
|
|
|
import logging
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG,
|
|
|
|
format='(%(threadName)-10s) %(message)s',
|
|
|
|
)
|
|
|
|
|
|
|
|
outputDir = "/home/crowd/output"
|
|
|
|
tmpImgFile = "/home/crowd/emo_in_file.jpg"
|
|
|
|
|
|
|
|
|
|
|
|
def handleLine(msg):
|
|
|
|
try:
|
|
|
|
j = json.loads(msg)
|
|
|
|
except Exception as e:
|
|
|
|
logging.error("Couldn't parse json " + msg)
|
|
|
|
return
|
|
|
|
|
|
|
|
#now we have json
|
|
|
|
logging.debug(j)
|
|
|
|
|
|
|
|
print " ".join([
|
|
|
|
'gphoto2',
|
|
|
|
"--port", "usb:",
|
|
|
|
"--capture-image-and-download",
|
|
|
|
"-I", "1", # photo every second
|
|
|
|
"--filename="+tmpImgFile, "--force-overwrite",
|
|
|
|
])
|
|
|
|
print " ".join([
|
|
|
|
'/home/crowd/build/opencv-webcam-demo/opencv-webcam-demo',
|
|
|
|
"--data", "/home/crowd/affdex-sdk/data",
|
|
|
|
"--faceMode", "1",
|
|
|
|
"--numFaces", "40",
|
|
|
|
"--draw", "1",
|
|
|
|
"-o", outputDir,
|
|
|
|
"-f", tmpImgFile,
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
# gphoto2 --port usb: --capture-image-and-download -I 1 --filename=~/test.jpg --force-overwrite
|
|
|
|
def captureImages():
|
|
|
|
procCapture = subprocess.Popen([
|
|
|
|
'gphoto2',
|
|
|
|
"--port", "usb:",
|
|
|
|
"--capture-image-and-download",
|
|
|
|
"-I", "1", # photo every second
|
|
|
|
"--filename="+tmpImgFile, "--force-overwrite",
|
|
|
|
],stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
while procCapture.poll() is None:
|
|
|
|
line = procCapture.stdout.readline()
|
|
|
|
if line == '':
|
|
|
|
continue
|
|
|
|
logging.debug(line)
|
|
|
|
if line.startswith("*** Error"):
|
|
|
|
raise Exception("Camera not found on USB, or unable to claim it")
|
|
|
|
return
|
|
|
|
|
|
|
|
def processImages():
|
|
|
|
procProcess = subprocess.Popen([
|
|
|
|
'/home/crowd/build/opencv-webcam-demo/opencv-webcam-demo',
|
|
|
|
"--data", "/home/crowd/affdex-sdk/data",
|
|
|
|
"--faceMode", "1",
|
|
|
|
"--numFaces", "40",
|
|
|
|
"--draw", "1",
|
|
|
|
"-o", outputDir,
|
|
|
|
"-f", tmpImgFile,
|
|
|
|
],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
while procProcess.poll() is None:
|
|
|
|
line = procProcess.stdout.readline()
|
|
|
|
if line == '':
|
|
|
|
continue
|
|
|
|
|
|
|
|
handleLine(line)
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
captureThread = threading.Thread(name='capture', target=captureImages)
|
|
|
|
processThread = threading.Thread(name='process', target=processImages)
|
|
|
|
|
|
|
|
captureThread.start()
|
|
|
|
processThread.start()
|