Skip to content

Commit d0ae4b7

Browse files
fixed everything.
fixed everything.
1 parent 4326520 commit d0ae4b7

16 files changed

+182
-180
lines changed

face.png

80.6 KB
Loading

face/face.png

60.8 KB
Loading

face/face1.png

-1.21 MB
Binary file not shown.

face/face2.png

19.9 KB
Loading

facifier/src/emotion_data_prep.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def extract_faces(emotions):
2020
if not os.path.exists('../data/emotion'):
2121
os.makedirs('../data/emotion')
2222
for emotion in emotions:
23-
print("Processing %s data..." % emotion)
23+
#print("Processing %s data..." % emotion)
2424
images = glob.glob('../data/raw_emotion/%s/*.jpg' % emotion)
2525
if not os.path.exists('../data/emotion/%s' % emotion):
2626
os.makedirs('../data/emotion/%s' % emotion)
@@ -31,6 +31,7 @@ def extract_faces(emotions):
3131
try:
3232
cv2.imwrite("../data/emotion/%s/%s.jpg" % (emotion, file_number + 1), face[0])
3333
except:
34+
output = "Error in processing image"
3435
print("Error in processing %s" % image)
3536

3637
print("Face extraction finished")

facifier/src/facifier.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ def start_webcam(model_emotion, model_gender, window_size, window_name='live', u
4242
cv2.destroyWindow(window_name)
4343

4444
def analyze_picture(model_emotion, model_gender, path, window_size, window_name='static'):
45+
image = cv2.imread(path, 1)
4546
#cv2.namedWindow(window_name, WINDOW_NORMAL)
4647
#cv2.namedWindow(window_name, WINDOW_NORMAL)
4748
#if window_size:
4849
# width, height = window_size
4950
# cv2.resizeWindow(window_name, width, height)
50-
51-
image = cv2.imread(path, 1)
5251
for normalized_face, (x, y, w, h) in find_faces(image):
5352
global emotion_prediction, gender_prediction, pemotion
5453
emotion_prediction = model_emotion.predict(normalized_face)
@@ -60,7 +59,7 @@ def analyze_picture(model_emotion, model_gender, path, window_size, window_name=
6059
cv2.putText(image, emotions[emotion_prediction[0]], (x,y-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,255), 2)
6160
pemotion = emotions[emotion_prediction[0]]
6261
if(pemotion == "afraid"):
63-
print("happy")
62+
print("sad")
6463
elif(pemotion == NONE):
6564
print("happy")
6665
else:
@@ -104,8 +103,7 @@ def analyze_picture(model_emotion, model_gender, path, window_size, window_name=
104103
if os.path.isfile(path):
105104
analyze_picture(fisher_face_emotion, fisher_face_gender, path, window_size=(1280, 720), window_name=window_name)
106105
quit()
107-
else:
108-
print("File not found!")
109-
else:
110-
print("Invalid input, exiting program.")
106+
#print("File not found!")
107+
#else:
108+
#print("Invalid input, exiting program.")
111109

facifier/src/lol.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
import sys
2-
print(sys.version)
2+
3+
a = 1;
4+
b = 3;
5+
6+
c = a + b;
7+
8+
9+
if(c == (b - a)):
10+
print("well it's correct")
11+
else:
12+
print("well it's wrong actally..")

facifier/src/main.c

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
5+
int main( int argc, char *argv[] )
6+
{
7+
8+
FILE *fp;
9+
char path[1035];
10+
11+
/* Open the command for reading. */
12+
fp = popen("python facifier.py", "r");
13+
if (fp == NULL) {
14+
printf("Failed to run command\n" );
15+
exit(1);
16+
}
17+
18+
/* Read the output a line at a time - output it. */
19+
while (fgets(path, sizeof(path)-1, fp) != NULL) {
20+
printf("%s", path);
21+
}
22+
23+
/* close */
24+
pclose(fp);
25+
26+
return 0;
27+
}

facifier/src/main.exe

131 KB
Binary file not shown.

hi.txt

+1
Large diffs are not rendered by default.

imageprocess.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
<?php
22

3+
include "link.php";
4+
35
if(!isset($_SESSION["logged"]) || $_SESSION["logged"] == 0)
46
{
57
//header("Location: signin.php");
68
}
79

8-
/*$image_name = $_FILES["userimage"]["tmp_name"];
9-
$actual_name = basename($_FILES["userimage"]["name"]);
10-
echo "image name: " . $image_name . "<br>";
11-
echo "actual name: " . $actual_name . "<br>";
12-
move_uploaded_file($image_name, "faces/$actual_name");*/
10+
$cmd = "main.exe";
11+
chdir("facifier/src");
12+
$output = array();
13+
exec("$cmd", $output);
1314

14-
//$command = escapeshellcmd('facifier/src/facifier.py');
15-
//$output = shell_exec($command);
15+
echo implode("<br>", $output)
1616

17-
$command = escapeshellcmd("python facifier/src/facifier.py");
17+
/*$command = escapeshellcmd("python facifier/src/facifier.py"); //image storage in front end (javascript)
1818
1919
$output = shell_exec($command);
2020
21-
echo $output;
21+
echo $output; */
22+
23+
/*sleep(3);
24+
25+
$ln = getlink($output);
2226
27+
header("Location: $ln");
28+
*/
2329
?>
2430

2531
<html>

link.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$emo = array("happy", "sad", "angry", "bored");
4+
5+
$rn = random_int(0, 3);
6+
7+
function getlink($output)
8+
{
9+
$link = "getsong.php?emotion=" . $emo[$rn];
10+
return $link;
11+
}
12+
13+
?>

main.exe

131 KB
Binary file not shown.

player.php

+44-162
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,20 @@
4040
</div>
4141
</div>
4242
<div class="right_container">
43-
<div class="label" >Scan From Camera</div>
44-
<canvas id="canvas" width="640" height="480"></canvas>
45-
<img id="photo" width="320px" height="320px" >
43+
<div class="label" ><button id="scan_btn" >Scan From Camera</button></div>
4644
<form action="imageprocess.php" method="post" enctype="multipart/form-data" >
47-
<video id="video" width="640" height="480" autoplay></video>
4845
<!--<input type="file" name="userimage" class="file_button" accept="image/*;capture=camera" value="Scan">-->
4946
<!--<input type="submit" value="upload" style="float: right; margin-right: 25px;">-->
5047
</form>
51-
<button id="snap">Snap Photo</button>
5248
</div>
5349
</div>
50+
<div class="cam" id="cam" >
51+
<canvas id="canvas" width="640" height="480"></canvas>
52+
<video id="video" width="640" height="480" autoplay></video>
53+
<button id="snap">Snap Photo</button>
54+
<button id="process" >Process</button>
55+
</div>
56+
<!--<img id="photo" width="320px" height="320px" >-->
5457
<div class="maincontainer" >
5558
<div class="leftcontainer" >
5659
<div class="player" >
@@ -97,7 +100,9 @@ class="controls" >Your browser doesn't allow this feature</audio>
97100
var angry_btn = document.getElementById("angry");
98101
var bored_btn = document.getElementById("bored");
99102
var music = document.getElementById("music");
100-
103+
var scan_btn = document.getElementById("scan_btn");
104+
105+
101106
var visualizer = document.getElementById("visualizer");
102107
var scene_path = "images/scene";
103108

@@ -124,171 +129,48 @@ class="controls" >Your browser doesn't allow this feature</audio>
124129
var canvas = document.getElementById('canvas');
125130
var context = canvas.getContext('2d');
126131
var video = document.getElementById('video');
132+
var cam = document.getElementById("cam");
133+
var process_btn = document.getElementById('process');
134+
var dataURL;
135+
136+
scan_btn.onclick = function()
137+
{
138+
closeWindow("sense_window");
139+
closeWindow("grey_mask");
140+
cam.style.display = "block";
141+
process_btn.style.display = "none";
142+
}
143+
144+
process_btn.onclick = function()
145+
{
146+
cam.style.display = "none";
147+
window.location = "imageprocess.php";
148+
}
127149

128150
// Trigger photo take
129151
document.getElementById("snap").addEventListener("click", function() {
130152
context.drawImage(video, 0, 0, 640, 480);
131-
});
132-
133-
/*var video;
134-
var webcamStream;
135-
136-
function startWebcam() {
137-
if (navigator.getUserMedia) {
138-
navigator.getUserMedia (
139-
140-
// constraints
141-
{
142-
video: true,
143-
audio: false
144-
},
145-
146-
// successCallback
147-
function(localMediaStream) {
148-
video = document.querySelector('video');
149-
video.src = window.URL.createObjectURL(localMediaStream);
150-
webcamStream = localMediaStream;
151-
},
152-
153-
// errorCallback
154-
function(err) {
155-
console.log("The following error occured: " + err);
156-
}
157-
);
158-
} else {
159-
console.log("getUserMedia not supported");
160-
}
161-
}
162-
163-
function stopWebcam() {
164-
webcamStream.stop();
165-
}
166-
//---------------------
167-
// TAKE A SNAPSHOT CODE
168-
//---------------------
169-
var canvas, ctx;
170-
171-
function init() {
172-
// Get the canvas and obtain a context for
173-
// drawing in it
174-
canvas = document.getElementById("myCanvas");
175-
ctx = canvas.getContext('2d');
176-
}
177-
178-
function snapshot() {
179-
// Draws current image from the video element into the canvas
180-
ctx.drawImage(video, 0,0, canvas.width, canvas.height);
181-
}*/
182-
183-
184-
/*(function() {
185-
// The width and height of the captured photo. We will set the
186-
// width to the value defined here, but the height will be
187-
// calculated based on the aspect ratio of the input stream.
153+
video.style.display = "none";
154+
canvas.style.display = "block";
188155

189-
var width = 320; // We will scale the photo width to this
190-
var height = 0; // This will be computed based on the input stream
156+
dataURL = canvas.toDataURL();
191157

192-
// |streaming| indicates whether or not we're currently streaming
193-
// video from the camera. Obviously, we start at false.
194-
195-
var streaming = false;
196-
197-
// The various HTML elements we need to configure or control. These
198-
// will be set by the startup() function.
199-
200-
var video = null;
201-
var canvas = null;
202-
var photo = null;
203-
var startbutton = null;
204-
205-
function startup() {
206-
video = document.getElementById('video');
207-
canvas = document.getElementById('canvas');
208-
photo = document.getElementById('photo');
209-
startbutton = document.getElementById('startbutton');
210-
211-
navigator.mediaDevices.getUserMedia({video: true, audio: false})
212-
.then(function(stream) {
213-
video.srcObject = stream;
214-
video.play();
215-
})
216-
.catch(function(err) {
217-
console.log("An error occurred: " + err);
218-
});
219-
220-
video.addEventListener('canplay', function(ev){
221-
if (!streaming) {
222-
height = video.videoHeight / (video.videoWidth/width);
223-
224-
// Firefox currently has a bug where the height can't be read from
225-
// the video, so we will make assumptions if this happens.
226-
227-
if (isNaN(height)) {
228-
height = width / (4/3);
229-
}
230-
231-
video.setAttribute('width', width);
232-
video.setAttribute('height', height);
233-
canvas.setAttribute('width', width);
234-
canvas.setAttribute('height', height);
235-
streaming = true;
236-
}
237-
}, false);
238-
239-
startbutton.addEventListener('click', function(ev){
240-
takepicture();
241-
ev.preventDefault();
242-
}, false);
243-
244-
clearphoto();
245-
}
246-
247-
// Fill the photo with an indication that none has been
248-
// captured.
249-
250-
function clearphoto() {
251-
var context = canvas.getContext('2d');
252-
context.fillStyle = "#AAA";
253-
context.fillRect(0, 0, canvas.width, canvas.height);
254-
255-
var data = canvas.toDataURL('image/png');
256-
photo.setAttribute('src', data);
158+
$.ajax({
159+
type: "POST",
160+
url: "saver.php",
161+
data: {
162+
imgBase64: dataURL
257163
}
258-
259-
// Capture a photo by fetching the current contents of the video
260-
// and drawing it into a canvas, then converting that to a PNG
261-
// format data URL. By drawing it on an offscreen canvas and then
262-
// drawing that to the screen, we can change its size and/or apply
263-
// other changes before drawing it.
264-
265-
function takepicture() {
266-
var context = canvas.getContext('2d');
267-
if (width && height) {
268-
canvas.width = width;
269-
canvas.height = height;
270-
context.drawImage(video, 0, 0, width, height);
271-
272-
var data = canvas.toDataURL('image/png');
273-
photo.setAttribute('src', data);
164+
}).done(function(o) {
165+
process_btn.style.display = "block";
166+
// If you want the file to be visible in the browser
167+
// - please modify the callback in javascript. All you
168+
// need is to return the url to the file, you just saved
169+
// and than put the image in your browser.
170+
});
171+
});
274172

275-
} else {
276-
clearphoto();
277-
}
278-
}
279173

280-
// Set up our event listener to run the startup process
281-
// once loading is complete.
282-
window.addEventListener('load', startup, false);
283-
})();*/
284-
285-
/*for(;;)
286-
{
287-
setInterval(function()
288-
{
289-
290-
}, 5000);
291-
}*/
292174

293175
function getRandomInt(max) {
294176
return Math.floor(Math.random() * Math.floor(max));

0 commit comments

Comments
 (0)