Merge branch 'master' of rubenvandeven.com:~/git/crowdcamera

This commit is contained in:
Ruben 2017-12-07 15:11:39 +01:00
commit b6ab33ab97
5 changed files with 86 additions and 40 deletions

View file

@ -7,7 +7,7 @@
var d1 = <?php echo require "output/talk1.json" ?>; var d1 = <?php echo require "output/talk1.json" ?>;
var d2 = <?php echo require "output/talk2.json" ?>; var d2 = <?php echo require "output/talk2.json" ?>;
var d3 = <?php echo require "output/talk3.json" ?>; //~ var d3 = <?php echo require "output/talk3.json" ?>;
</script> </script>
<style type="text/css"> <style type="text/css">
@ -22,10 +22,10 @@ var d3 = <?php echo require "output/talk3.json" ?>;
overflow-x:auto; overflow-x:auto;
} }
#presentations{ #presentations{
width:300%; width:200%;
} }
#presentations .presentation{ #presentations .presentation{
width:33%; width:50%;
float:left; float:left;
} }
#presentations .presentation div.plot{ #presentations .presentation div.plot{
@ -59,8 +59,15 @@ var d3 = <?php echo require "output/talk3.json" ?>;
} }
#imgwrap div{
display:block;
color:#999;
font-size:80%;
}
#imgwrap img{ #imgwrap img{
width:90%; height:7em;
min-width: 3em;
background:#ccc;
margin-left:2%; margin-left:2%;
margin-top:1em; margin-top:1em;
} }
@ -78,6 +85,12 @@ var d3 = <?php echo require "output/talk3.json" ?>;
<div id="scroller"> <div id="scroller">
<div id='presentations'> <div id='presentations'>
<div class='presentation'>
<h1>Penousal Machado</h1>
<div class='stats' id='plot2-stats'></div>
<div class='plot' id="plot2-div"></div>
</div>
<div class='presentation'> <div class='presentation'>
<h1>Orit Halpern</h1> <h1>Orit Halpern</h1>
<div class='stats' id='plot1-stats'></div> <div class='stats' id='plot1-stats'></div>
@ -85,22 +98,18 @@ var d3 = <?php echo require "output/talk3.json" ?>;
</div> </div>
<div class='presentation'> <!--
<h1>Penousal Machado</h1>
<div class='stats' id='plot2-stats'></div>
<div class='plot' id="plot2-div"></div>
</div>
<div class='presentation'> <div class='presentation'>
<h1>Nicolas Maigret</h1> <h1>Nicolas Maigret</h1>
<div class='stats' id='plot3-stats'></div> <div class='stats' id='plot3-stats'></div>
<div class='plot' id="plot3-div"></div> <div class='plot' id="plot3-div"></div>
</div> </div>
-->
</div> </div>
</div> </div>
<div id='imgwrap'> <div id='imgwrap'>
<img src="" id="hoverimg">
</div> </div>
<script type='text/javascript'> <script type='text/javascript'>
@ -251,19 +260,19 @@ for(var i in facialParameters){
labelEl.title = "Expressiveness: " + d1ParamExpressiveness[param] + ", " + d2ParamExpressiveness[param] + ", " + d3ParamExpressiveness[param]; labelEl.title = "Expressiveness: " + d1ParamExpressiveness[param] + ", " + d2ParamExpressiveness[param] + ", " + d3ParamExpressiveness[param];
} }
var imgEl = document.getElementById("hoverimg"); var imgwrapEl = document.getElementById("imgwrap");
var plot1Div = document.getElementById('plot1-div'); var plot1Div = document.getElementById('plot1-div');
var plot2Div = document.getElementById('plot2-div'); var plot2Div = document.getElementById('plot2-div');
var plot3Div = document.getElementById('plot3-div'); // var plot3Div = document.getElementById('plot3-div');
var stats1Div = document.getElementById('plot1-stats'); var stats1Div = document.getElementById('plot1-stats');
var stats2Div = document.getElementById('plot2-stats'); var stats2Div = document.getElementById('plot2-stats');
var stats3Div = document.getElementById('plot3-stats'); // var stats3Div = document.getElementById('plot3-stats');
function drawGraphs(){ function drawGraphs(){
params = getCheckedParams(); params = getCheckedParams();
drawGraph("talk1", plot1Div, d1, params, stats1Div); drawGraph("talk1", plot1Div, d1, params, stats1Div);
drawGraph("talk2", plot2Div, d2, params, stats2Div); drawGraph("talk2", plot2Div, d2, params, stats2Div);
drawGraph("talk3", plot3Div, d3, params, stats3Div); //~ drawGraph("talk3", plot3Div, d3, params);
} }
@ -470,12 +479,20 @@ function drawGraph(id, targetEl, d, params, statsEl) {
//~ }); //~ });
targetEl.on('plotly_hover', function (data){ targetEl.on('plotly_hover', function (data){
let HTML = "";
var points = data.points[0], var points = data.points[0],
pointNum = points.pointNumber; pointNum = points.pointNumber;
console.log(pointNum, d['windows'][pointNum]['startFrame'], data); console.log(d);
imgEl.src = "/images.php?i="+d['windows'][pointNum]['startFrame']+"&params="+params.join() + "&nr=" + d['outputNr'] ; for(let i in d['windows'][pointNum]['frames']) {
console.log(pointNum, d['windows'][pointNum]['frames'][i], data);
//~ imgEl.src = "/images.php?i="+d['windows'][pointNum]['frames'][i]+"&params="+params.join() + "&nr=" + d['outputNr'] ;
HTML+= "<div>"+d['windows'][pointNum]['frames'][i]+"<img src=\"/images.php?i="+d['windows'][pointNum]['frames'][i]+"&params="+params.join() + "&nr=" + d['outputNr'] +"\"></div>" ;
}
imgwrapEl.innerHTML = HTML;
var audio = new Audio('output/'+d['outputNr']+'/'+d['windows'][pointNum]['startFrame']+'.wav'); var audio = new Audio('output/'+d['outputNr']+'/'+d['windows'][pointNum]['startFrame']+'.wav');
audio.play(); audio.play();
//~ Plotly.Fx.hover('plot-div',[ //~ Plotly.Fx.hover('plot-div',[
//~ { curveNumber:0, pointNumber:pointNum }, //~ { curveNumber:0, pointNumber:pointNum },
//~ { curveNumber:1, pointNumber:pointNum }, //~ { curveNumber:1, pointNumber:pointNum },

View file

@ -61,21 +61,28 @@ usort($json['faces'], function ($f1, $f2) {
return $f1['diff'] > $f2['diff'] ? -1 : 1; return $f1['diff'] > $f2['diff'] ? -1 : 1;
}); });
$targetIm = imagecreatetruecolor(1920, 1080); $i = 0;
$faceDim = 120;
$faceMargin = 20;
$faceCount = count($json['faces']);
$widthNr = max(1, $faceCount);
$targetIm = imagecreatetruecolor(($faceDim+$faceMargin)* $widthNr, $faceDim + 20);
$white = imagecolorallocate($targetIm, 255, 255, 255); $white = imagecolorallocate($targetIm, 255, 255, 255);
imagefill($targetIm, 0, 0, $white); imagefill($targetIm, 0, 0, $white);
$i = 0; $i = 0;
$faceDim = 120; $faceDim = 120;
$faceMargin = 20; $faceMargin = 20;
$itemsPerRow = (int) 1080 / ($faceDim + $faceMargin); //~ $itemsPerRow = (int) 1080 / ($faceDim + $faceMargin);
$maxDiff = sqrt(count($params) * 100); $maxDiff = sqrt(count($params) * 100);
foreach($json['faces'] as $face) { foreach($json['faces'] as $face) {
$posX = $i % $itemsPerRow; $posX = $i % $itemsPerRow;
$posY = (int) ($i / $itemsPerRow); //~ $posY = (int) ($i / $itemsPerRow);
//~
$destX = $posX * ($faceDim + $faceMargin); //~ $destX = $posX * ($faceDim + $faceMargin);
$destY = $posY * ($faceDim + $faceMargin); //~ $destY = $posY * ($faceDim + $faceMargin);
$destX = $i * ($faceDim + $faceMargin);
$destY = 0;
imagecopyresampled ( $targetIm , $im , $destX , $destY , (int) $face['rect']['x'] , (int) $face['rect']['y'] , $faceDim , $faceDim , (int) $face['rect']['w'], (int) $face['rect']['h']); imagecopyresampled ( $targetIm , $im , $destX , $destY , (int) $face['rect']['x'] , (int) $face['rect']['y'] , $faceDim , $faceDim , (int) $face['rect']['w'], (int) $face['rect']['h']);
@ -85,7 +92,6 @@ foreach($json['faces'] as $face) {
imagettftext($targetIm, 12, 0, $destX, $destY + $faceDim + $faceMargin/1.2, $colorBg, "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", round($face['diff'],2)); imagettftext($targetIm, 12, 0, $destX, $destY + $faceDim + $faceMargin/1.2, $colorBg, "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", round($face['diff'],2));
$i++; $i++;
} }
$im = $targetIm; $im = $targetIm;
/* /*

View file

@ -245,6 +245,18 @@ int main(int argsc, char ** argsv)
int frameNrIn = 1; int frameNrIn = 1;
int frameNrOut = 1; int frameNrOut = 1;
// increase number to current pos:
while(true) {
char buff[100];
snprintf(buff, sizeof(buff), (use_segments ? "segment%06d.json" : "frame%06d.json"), frameNrIn);
boost::filesystem::path jsonPath = outPath / buff;
if ( boost::filesystem::exists( jsonPath.native() )) {
frameNrIn++;
frameNrOut++;
} else {
break;
}
}
std::time_t lastImgUpdate(0); std::time_t lastImgUpdate(0);
int seconds = 1; int seconds = 1;
while(true){ //(cv::waitKey(20) != -1); while(true){ //(cv::waitKey(20) != -1);

View file

@ -217,6 +217,9 @@ class Window:
return np.std(vectors) return np.std(vectors)
def getAverageV(self, params): def getAverageV(self, params):
# when no faces, return faux vector
if len(self.getFaces()) < 1:
return [0.0 for p in params]
vectors = [f.getCharacteristicVector(params) for f in self.getFaces()] vectors = [f.getCharacteristicVector(params) for f in self.getFaces()]
vAvg = np.mean(vectors, axis=0) vAvg = np.mean(vectors, axis=0)
return vAvg return vAvg
@ -458,12 +461,13 @@ def getGraphData(frames, params, window_size, outputNr):
""" """
collection = WindowCollection(window_size, frames) collection = WindowCollection(window_size, frames)
windows = collection.windows windows = collection.windows
jsonOutput = {'windows':[], 'outputNr': outputNr} jsonOutput = {'windows':[], 'outputNr': outputNr, 'window_size': window_size}
for window in windows: for window in windows:
w = { w = {
'start': window.getStartTime().strftime('%Y-%m-%d %H:%M:%S'), 'start': window.getStartTime().strftime('%Y-%m-%d %H:%M:%S'),
'end': window.getEndTime().strftime('%Y-%m-%d %H:%M:%S'), 'end': window.getEndTime().strftime('%Y-%m-%d %H:%M:%S'),
'startFrame': window.frames[0].name, 'startFrame': window.frames[0].name,
'frames': [frame.name for frame in window.frames],
'params': {}, 'params': {},
'param_values': {}, 'param_values': {},
} }

View file

@ -34,23 +34,27 @@ nextOutNr = segmentCount
while True: while True:
nextJpg = os.path.join(args.frameOutput, "frame%06d.jpg" % nextInNr) nextJpg = os.path.join(args.frameOutput, "frame%06d.jpg" % nextInNr)
nextInJson = os.path.join(args.frameOutput, "frame%06d.json" % nextInNr) nextInJson = os.path.join(args.frameOutput, "frame%06d.json" % nextInNr)
while os.path.exists(nextJpg) and not os.path.exists(nextInJson): while os.path.exists(nextJpg):
print("(SPLIT) Found: {}".format(nextJpg)) if not os.path.exists(nextInJson):
img = Image.open(nextJpg) print("(SPLIT) Found: {}".format(nextJpg))
img = Image.open(nextJpg)
segments = getSectionsForSize(img.size)
segments = getSectionsForSize(img.size)
for i, segment in enumerate(segments):
segmentImg = img.crop(segment) for i, segment in enumerate(segments):
segmentNr = (nextInNr-1) * segmentCount + i + 1 # start at 1, increment from there segmentImg = img.crop(segment)
segmentFilename = os.path.join(args.segmentDir, "segment%06d.jpg" % segmentNr) segmentNr = (nextInNr-1) * segmentCount + i + 1 # start at 1, increment from there
segmentImg.save(segmentFilename, quality=90) segmentFilename = os.path.join(args.segmentDir, "segment%06d.jpg" % segmentNr)
print("(SPLIT) Created: {}".format(segmentFilename)) segmentImg.save(segmentFilename, quality=90)
print("(SPLIT) Created: {}".format(segmentFilename))
else:
print("(SPLIT) Skip: {}".format(nextJpg))
nextInNr += 1 nextInNr += 1
nextJpg = os.path.join(args.frameOutput, "frame%06d.jpg" % nextInNr) nextJpg = os.path.join(args.frameOutput, "frame%06d.jpg" % nextInNr)
nextInJson = os.path.join(args.frameOutput, "frame%06d.jpg" % nextInNr) nextInJson = os.path.join(args.frameOutput, "frame%06d.json" % nextInNr)
continue
nextJson = os.path.join(args.segmentDir, "segment%06d.json" % nextOutNr) nextJson = os.path.join(args.segmentDir, "segment%06d.json" % nextOutNr)
while os.path.exists(nextJson): while os.path.exists(nextJson):
print("(MERGE) Found: {}".format(nextJson)) print("(MERGE) Found: {}".format(nextJson))
@ -88,8 +92,11 @@ while True:
print("(MERGE) Wrote: {}".format(jsonOutFilename)) print("(MERGE) Wrote: {}".format(jsonOutFilename))
print("(MERGE) Cleanup segments for frame {}".format(frameOutNr)) print("(MERGE) Cleanup segments for frame {}".format(frameOutNr))
for imgName in segmentImages: for imgName in segmentImages:
print("(MERGE) \t Unlink {}".format(imgName)) if os.path.exists(imgName):
os.unlink(imgName) print("(MERGE) \t Unlink {}".format(imgName))
os.unlink(imgName)
else:
print("(MERGE) \t Already unlinked {}".format(imgName))
nextOutNr += segmentCount nextOutNr += segmentCount
nextJson = os.path.join(args.segmentDir, "segment%06d.json" % nextOutNr) nextJson = os.path.join(args.segmentDir, "segment%06d.json" % nextOutNr)