Skip to content

Commit

Permalink
Merge pull request #2 from Dagiopia/master
Browse files Browse the repository at this point in the history
all in one test and mods
  • Loading branch information
smigad authored Apr 23, 2018
2 parents 443e49c + 9064b39 commit c75eec1
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 13 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ add_executable(SaliencyTest examples/sense/vision/SaliencyTest.cpp)
target_link_libraries(SaliencyTest sensor_vision ${OpenCV_LIBS} ${EXTRA_LIBS})

add_executable(SaliencyTest2 examples/sense/vision/SaliencyTest2.cpp)
target_link_libraries(SaliencyTest2 sensor_vision ${OpenCV_LIBS} ${EXTRA_LIBS})
target_link_libraries(SaliencyTest2 sensor_vision ${OpenCV_LIBS} ${EXTRA_LIBS})

add_executable(AllTest examples/sense/vision/AllTest.cpp)
target_link_libraries(AllTest sensor_vision ${OpenCV_LIBS} ${EXTRA_LIBS})

if(raspicam_FOUND)
add_executable(RaspiVisionTest examples/sense/vision/RaspiVisionTest.cpp)
Expand Down
163 changes: 163 additions & 0 deletions examples/sense/vision/AllTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
Project: OpenCogER
File: AllTest.cpp
Author: Dagim Sisay
License: AGPL
Date: April, 2018
*/


#include <iostream>
#include <string>
#include <signal.h>

#include "sense/vision/CamCapture.hpp"
#include "sense/vision/ITColor2Gray.hpp"
#include "sense/vision/ITEqualizeHist.hpp"
#include "sense/vision/ITDetectFace.hpp"
#include "sense/vision/ITDetectSmile.hpp"
#include "sense/vision/FacialLandMark.hpp"
#include "sense/vision/ITDetectHand.hpp"
#include "sense/vision/FingersCount.hpp"
#include "sense/vision/DSaliency.hpp"
#include "sense/vision/BoxTrackerThread.hpp"


#define _NEED_GUI_
#define _NEED_TIME_INFO_

#define NO_FLMS 26
#define SCALE 0.1

using namespace std;
using namespace cv;


float avg_time_pf, en_time, acc, avg_oh, avg_nh, avg_nf, avg_of;
uint64_t st_time;
int n_f, nh, oh, nf, of;


void print_report()
{
avg_time_pf = acc / n_f;
avg_nh /= nh;
avg_oh /= oh;
avg_of /= of;
avg_nf /= nf;
printf("\nAverage Time per Frame (no Face): %f\n", avg_nf);
printf("Average Time per Frame (on Face): %f\n", avg_of);
printf("Average Time per Frame (no Hand): %f\n", avg_nh);
printf("Average Time per Frame (on Hand): %f\n", avg_oh);
printf("Average Time per Frame: %f\n\n", avg_time_pf);
}


void sigint_handler(int sig)
{
cout<<"Caught SIGINT... Exiting!\n";
#ifdef _NEED_TIME_INFO_
print_report();
#endif //_NEED_TIME_INFO_
exit(0);
}


int main(int argc, char **argv)
{
#ifdef _NEED_TIME_INFO_
avg_nh = avg_oh = avg_of = avg_nf = avg_time_pf = 0;
oh = nh = of = nf = n_f = 0;
#endif //_NEED_TIME_INFO_
bool face_found = false;
bool hand_found = false;

signal(SIGINT, sigint_handler);
CamCapture cc("cam", 320, 240, 0, 20);
if (!cc.isOk()){std::cout<<std::endl<<cc.getState()<<std::endl;return -1;}

Mat frame, img, img2;

ITColor2Gray c2g("c2g1");
ITEqualizeHist eh("eh1");
ITDetectFace fcd("fcd1");
ITDetectSmile smd("smd1");
FacialLandMark flm;
ITDetectHand dh("dh1");
FingersCount fc(true);
DSaliency sal_d(SAL_STATIC, SAL_FINE_GRAINED);

vector <Rect> faces, hands;
vector <facial_lms> f_lms;
facial_lms shape;
Rect2d box2d;
Rect box;
vector<vector<Point> > cntrs;
vector<Vec4i> hier;


BoxTrackerThread *bt;

while (true)
{
#ifdef _NEED_TIME_INFO_
st_time = getTickCount();
#endif //_NEED_TIME_INFO_
frame = cc.getCurrentFrame();
img = eh.Transform(c2g.Transform(frame));
faces = fcd.Transform(img);

f_lms.clear();
flm.get_lm_points(frame, faces, &f_lms);
for (int i = 0; i < f_lms.size(); ++i){
face_found = true;
shape = f_lms[i];
#ifdef _NEED_GUI_
for (int j = 0; j < NO_FLMS; ++j)
circle(frame, Size(shape.part(j).x(), shape.part(j).y()), 1,
CV_RGB(0, 255, 0), 1.5);
#endif //_NEED_GUI_
}
threshold(img, img, 70, 255, CV_THRESH_BINARY_INV | CV_THRESH_OTSU);
hands = dh.Transform(img);
for (int i = 0; i < hands.size(); ++i){
hand_found = true;
img2 = Mat(img, Rect(hands[i].x - hands[i].x*SCALE,
hands[i].y - hands[i].y*SCALE,
hands[i].width + hands[i].width*SCALE,
hands[i].height + hands[i].height*SCALE));
#ifdef _NEED_GUI_
putText(frame, to_string(fc.num_fingers(img2)), Point(20, 20),
FONT_HERSHEY_COMPLEX_SMALL, 1.5, CV_RGB(255, 0, 0), 2, CV_AA);
cvtColor(img2, img2, COLOR_GRAY2BGR);
for(size_t j = 0; j < fc.f_tips.size(); ++j)
circle(img2, fc.f_tips[j], 2, CV_RGB(255, 0, 0), 2);
imshow("hand", img2);
#endif //_NEED_GUI_
}
#ifdef _NEED_GUI_
imshow("feed", frame);
if(27 == waitKey(10))
break;
#endif //_NEED_GUI_

#ifdef _NEED_TIME_INFO_
en_time = (float)((getTickCount() - st_time) / getTickFrequency());
if (hand_found){ avg_oh += en_time; oh++; }
else { avg_nh += en_time; nh++; }
if (face_found){ avg_of += en_time; of++; }
else { avg_nf += en_time; nf++; }
acc += en_time;
n_f++;
#endif //_NEED_TIME_INFO_

face_found = false;
hand_found = false;
} // while (true)

#ifdef _NEED_TIME_INFO_
print_report();
#endif //_NEED_TIME_INFO_

return 0;
}
12 changes: 6 additions & 6 deletions examples/sense/vision/FaceLandMarkTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ int main(int argc, char** argv)
for (uint8_t idx = 0; idx < f_lms.size(); idx++)
{
facial_lms shape = f_lms[idx];
// for(uint8_t i = 0; i < 30; i++)
// cv::circle(frame, cv::Size(shape.part(i).x(), shape.part(i).y()),
// 2, CV_RGB(0, 255, 0), 2);
for(uint8_t i = 0; i < 26; i++)
cv::circle(frame, cv::Size(shape.part(i).x(), shape.part(i).y()),
1.5, CV_RGB(0, 255, 0), 1.5);
}
//cv::imshow("face landmark", frame);
//if(27 == cv::waitKey(10))
// break;
cv::imshow("face landmark", frame);
if(27 == cv::waitKey(10))
break;
en_time = (float)((getTickCount() - st_time) / getTickFrequency());
printf("Frame #%d, Time: %f\n", n_f, en_time);
acc += en_time;
Expand Down
5 changes: 2 additions & 3 deletions examples/sense/vision/FingersCountTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ int main(int argc, char **argv)

cv::Mat frame, img, img2;
std::vector<cv::Rect> hands;
std::vector<std::string> snum({"one", "two", "three", "four", "five", "si", "sev"});

while (true)
{
Expand All @@ -45,8 +44,8 @@ int main(int argc, char **argv)
hands[i].y - hands[i].y*SCALE,
hands[i].width + hands[i].width*SCALE,
hands[i].height + hands[i].height*SCALE));
cv::putText(frame, snum[fc.num_fingers(img)], cv::Point(20, 20),
cv::FONT_HERSHEY_COMPLEX_SMALL, 0.8, CV_RGB(50, 50, 50), 2,
cv::putText(frame, std::to_string(fc.num_fingers(img)), cv::Point(20, 20),
cv::FONT_HERSHEY_COMPLEX_SMALL, 1.5, CV_RGB(50, 50, 50), 2,
CV_AA);
cv::cvtColor(img, img2, COLOR_GRAY2BGR);
for(size_t j = 0 ; j < fc.f_tips.size(); j++)
Expand Down
1 change: 1 addition & 0 deletions examples/sense/vision/VisionTestFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <iostream>
#include <cstring>
#include <vector>
#include <signal.h>

#include "sense/vision/CamCapture.hpp"
#include "sense/vision/ITColor2Gray.hpp"
Expand Down
16 changes: 16 additions & 0 deletions func_times
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,19 @@ Face Landmark (26 parts)
Average Time per Frame (no Face): 0.037780
Average Time per Frame (on Face): 0.049697
Average Time per Frame: 0.039970



---------------------------------------------
[ All in One ]
Face Landmark (26 parts) and FingersCount
Average Time per Frame (no Face): 0.031070
Average Time per Frame (on Face): 0.035642
Average Time per Frame (no Hand): 0.036242
Average Time per Frame (on Hand): 0.032650
Average Time per Frame: 0.034204



Face Landmark (26 parts) 2 faces and FingersCount

4 changes: 2 additions & 2 deletions include/sense/vision/FingersCount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
at current hand based on size or distance
from other points or whatever
*/
#define MIN_DEPTH 5.0
#define MAX_DEPTH 50.0
#define MIN_DEPTH 15.0
#define MAX_DEPTH 70.0

typedef std::vector<cv::Point> VP;
typedef std::vector<VP> VVP;
Expand Down
2 changes: 1 addition & 1 deletion sense/vision/detect/FingersCount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ uint8_t FingersCount::num_fingers(cv::Mat hand)
cv::convexHull(cntr, hull, false);
if(hull.size() > 3)
cv::convexityDefects(cntr, hull, defects);
count = 0;
count = 1;
VV4i::const_iterator d_it = defects.begin();
if(debug) printf("-----------------\n"); //XXX remove
while(d_it != defects.end())
Expand Down

0 comments on commit c75eec1

Please sign in to comment.