-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* video test * add minicaffe support * Update README.md
- Loading branch information
Showing
8 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CPP code for JFDA | ||
================= | ||
|
||
View video demo on YouTube [here](https://www.youtube.com/watch?v=Ee9UT9Zf98s). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
ffmpeg -i ./build/test.mp4 -f mp3 -vn ./build/test.mp3 | ||
|
||
ffmpeg -i ./build/test.mp3 -i ./build/result.avi -f mp4 -y ./build/result.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <iostream> | ||
#include "./jfda.hpp" | ||
#include "caffe/caffe.hpp" | ||
#include <opencv2/core/core.hpp> | ||
#include <opencv2/highgui/highgui.hpp> | ||
|
||
using namespace cv; | ||
using namespace std; | ||
using namespace jfda; | ||
|
||
int main(int argc, char* argv[]) { | ||
VideoCapture cap("./test.mp4"); | ||
if (!cap.isOpened()) { | ||
cout << "Can\'t open test.mp4" << endl; | ||
return 0; | ||
} | ||
double rate = cap.get(CV_CAP_PROP_FPS); | ||
double width = cap.get(CV_CAP_PROP_FRAME_WIDTH); | ||
double height = cap.get(CV_CAP_PROP_FRAME_HEIGHT); | ||
int fourcc = CV_FOURCC('X', 'V', 'I', 'D'); | ||
VideoWriter writer("./result.avi", fourcc, rate, Size(width, height), true); | ||
string proto_dir = "../../proto/"; | ||
string model_dir = "../../model/"; | ||
JfdaDetector detector(proto_dir + "p.prototxt", model_dir + "p.caffemodel", | ||
proto_dir + "r.prototxt", model_dir + "r.caffemodel", | ||
proto_dir + "o.prototxt", model_dir + "o.caffemodel", | ||
proto_dir + "l.prototxt", model_dir + "l.caffemodel", 0); | ||
detector.SetMinSize(24); | ||
Mat frame; | ||
caffe::Profiler* profiler = caffe::Profiler::Get(); | ||
while (cap.read(frame)) { | ||
int64_t t1 = profiler->Now(); | ||
vector<FaceInfo> faces = detector.Detect(frame); | ||
int64_t t2 = profiler->Now(); | ||
double fps = 1000000 / (t2 - t1); | ||
for (int i = 0; i < faces.size(); i++) { | ||
FaceInfo& face = faces[i]; | ||
cv::rectangle(frame, face.bbox, Scalar(0, 0, 255), 2); | ||
for (int j = 0; j < 5; j++) { | ||
cv::circle(frame, face.landmark5[j], 2, Scalar(0, 255, 0), -1); | ||
} | ||
} | ||
char buff[30]; | ||
sprintf(buff, "%.2f FPS", fps); | ||
cv::putText(frame, buff, Point2f(0, 10), FONT_HERSHEY_PLAIN, 1, Scalar(0, 255, 0)); | ||
writer.write(frame); | ||
cv::imshow("frame", frame); | ||
if (waitKey(1) >= 0) { | ||
break; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# pylint: disable=bad-indentation, no-member, invalid-name, line-too-long | ||
from .detector import JfdaDetector | ||
import minicaffe as caffe | ||
|
||
|
||
class MiniCaffeDetector(JfdaDetector): | ||
|
||
def __init__(self, nets): | ||
assert len(nets) in [2, 4, 6, 8], 'wrong number of nets' | ||
self.pnet, self.rnet, self.onet, self.lnet = None, None, None, None | ||
if len(nets) >= 2: | ||
self.pnet = caffe.Net(nets[0], nets[1]) | ||
if len(nets) >= 4: | ||
self.rnet = caffe.Net(nets[2], nets[3]) | ||
if len(nets) >= 6: | ||
self.onet = caffe.Net(nets[4], nets[5]) | ||
if len(nets) >= 8: | ||
self.lnet = caffe.Net(nets[6], nets[7]) | ||
self.pnet_single_forward = False |