Commit 9466c72f by wangquyuan

add by wqy

1 parent ae367ce4
......@@ -3,4 +3,5 @@ RUN apt-get update && apt-get install -y libjpeg8 libpng12-dev libjasper-dev lib
COPY ./ /package
RUN chmod a+x /package/yuexinserver
ENV LD_LIBRARY_PATH=/package/lib:/package:$LD_LIBRARY_PATH
ENV PATH=/package:$PATH
WORKDIR /package
......@@ -43,6 +43,6 @@ bool is_space_char(unsigned char c);
int skip_space_chars(const std::string &str, std::string::size_type nbegin);
int parse_http_parameters(const std::string & body, std::map<std::string,std::string> &paramters);
int myexec(const std::string &cmd, std::string &result);
#endif
......@@ -599,6 +599,15 @@ static std::string do_query_face_feature( const std::string &body )
SeetaPointF points[5];
face_landmarker5( img, faces.data[index].pos, points );
std::vector<float> features = face_recognizer( img, points );
std::cout << "features: " << features.size() << std::endl;
for(int i=0; i<features.size(); i++)
{
if(i % 16 == 0)
std::cout << "\n";
std::cout << ", " << features[i];
}
std::cout << std::endl;
std::string strtmp( ( const char * )features.data(), int( features.size() * sizeof( float ) ) );
std::string enbase64 = base64_encode( strtmp );
......@@ -892,8 +901,14 @@ static int recognize( seeta::HeartRateDetector *heartrate, cv::Mat &mat, const S
return 0;
}
void Rotate(const cv::Mat & src, cv::Mat &dst, int rotate)
{
cv::Point2f center(src.cols/2, src.rows/2);
cv::Mat m = getRotationMatrix2D(center, rotate, 1);
warpAffine(src, dst, m, cv::Size(src.cols,src.rows));
}
static void do_heart_rate( const std::string &videofile, int *rate, void *hearts )
static void do_heart_rate( const std::string &videofile, int nrotate, int *rate, void *hearts )
{
*rate = 0;
std::vector<int> * phearts = (std::vector<int> *)hearts;
......@@ -919,11 +934,14 @@ static void do_heart_rate( const std::string &videofile, int *rate, void *hearts
}
int fps = m_capture->get( cv::CAP_PROP_FPS);
std::cout << "do_heart fps:" << fps << std::endl;
if(fps < 1 )
{
fps = 20;
}else if (fps > 50)
{
fps = 20;
}
m_heartrate = new seeta::HeartRateDetector;
m_heartrate->set_frame_number( 300 );
m_heartrate->reset();
......@@ -964,17 +982,30 @@ static void do_heart_rate( const std::string &videofile, int *rate, void *hearts
continue;
}
//cv::Mat mat2;
//cv::Size size (VIDEO_WIDTH, VIDEO_HEIGHT);
//cv::resize(mat, mat2, size, 0, 0, cv::INTER_CUBIC);
//mat = mat2.clone();
cv::Mat mat2;
SeetaImageData img;
img.width = mat.cols;
img.height = mat.rows;
img.channels = mat.channels();
img.data = mat.data;
if(nrotate != 0)
{
Rotate(mat, mat2, nrotate);
img.width = mat2.cols;
img.height = mat2.rows;
img.channels = mat2.channels();
img.data = mat2.data;
}else
{
img.width = mat.cols;
img.height = mat.rows;
img.channels = mat.channels();
img.data = mat.data;
}
//cv::cvtColor(mat, mat2, cv::COLOR_BGR2RGB);
auto faces = face_detector( img );
......@@ -998,7 +1029,14 @@ static void do_heart_rate( const std::string &videofile, int *rate, void *hearts
value = 0.0;
//std::cout << "-----num:" << num << std::endl;
int nret = recognize( m_heartrate, mat, img, faces.data[index].pos, value );
int nret = 0;
if(nrotate == 0)
{
nret = recognize( m_heartrate, mat, img, faces.data[index].pos, value );
}else
{
nret = recognize( m_heartrate, mat2, img, faces.data[index].pos, value );
}
if( nret == 0 )
{
//std::cout << "-----rate:" << value << std::endl;
......@@ -1073,7 +1111,7 @@ static int geteyecount(seeta::EyeStateDetector::EYE_STATE oldstate, seeta::EyeSt
static void do_video( const std::string &videofile, int frameNum, int *eyes,
static void do_video( const std::string &videofile, int frameNum, int nrotate, int *eyes,
std::vector<std::vector<float>> &face_features,
std::vector<std::vector<float>> &face_poses,
std::vector<std::vector<float>> &face_actions,
......@@ -1098,12 +1136,13 @@ static void do_video( const std::string &videofile, int frameNum, int *eyes,
return;
}
/*
int fps = m_capture->get( cv::CAP_PROP_FPS);
if(fps < 1 )
{
fps = 20;
}
*/
//std::chrono::system_clock::time_point starttimer = std::chrono::system_clock::now();
//std::chrono::system_clock::time_point lasttimer;
//std::vector<double> rates;
......@@ -1148,12 +1187,29 @@ static void do_video( const std::string &videofile, int frameNum, int *eyes,
//cv::resize(mat, mat2, size, 0, 0, cv::INTER_CUBIC);
//mat = mat2.clone();
cv::Mat mat2;
SeetaImageData img;
img.width = mat.cols;
img.height = mat.rows;
img.channels = mat.channels();
img.data = mat.data;
if(nrotate != 0)
{
Rotate(mat, mat2, nrotate);
img.width = mat2.cols;
img.height = mat2.rows;
img.channels = mat2.channels();
img.data = mat2.data;
}else
{
img.width = mat.cols;
img.height = mat.rows;
img.channels = mat.channels();
img.data = mat.data;
}
//SeetaImageData img;
//img.width = mat.cols;
//img.height = mat.rows;
//img.channels = mat.channels();
//img.data = mat.data;
//cv::cvtColor(mat, mat2, cv::COLOR_BGR2RGB);
auto faces = face_detector( img );
......@@ -1441,7 +1497,34 @@ static int parse_boundary_paramters( std::string &filename, const std::string &b
}
static int get_video_rotate(const std::string & filename)
{
std::string cmd = "ffmpeg -i ";
cmd += filename;
cmd += " 2>&1";
std::cout << "cmd:" << cmd << std::endl;
std::string result;
int ret = myexec(cmd, result);
if(ret != 0 )
{
std::cout << "run " << cmd << " failed";
return 0;
}
int nfind = result.find("rotate :");
if(nfind >= 0)
{
int nfind2 = result.find("\n", nfind + 17);
if (nfind2 >= 0)
{
//std::cout << "rotate:" << result.substr(nfind + 17, nfind2 - nfind - 17) << std::endl;
int nrotate = atoi(result.substr(nfind+17, nfind2 - nfind - 17).c_str());
std::cout << "nrotate:" << nrotate << std::endl;
return nrotate;
}
}
return 0;
}
......@@ -1536,8 +1619,11 @@ void on_http( httpserver *s, websocketpp::connection_hdl hdl )
if(nret == 0)
{
std::cout << "upload file:" << filename << std::endl;
std::thread heartrate_thread(do_heart_rate, filename, &hearts, &heart_beats);
do_video(filename, frameNum, &eyes, face_features,
int nrotate = get_video_rotate(filename);
nrotate = nrotate * -1;
std::thread heartrate_thread(do_heart_rate, filename, nrotate, &hearts, &heart_beats);
do_video(filename, frameNum, nrotate, &eyes, face_features,
face_poses,face_actions,face_emotions, blink_eyes);
heartrate_thread.join();
......
......@@ -142,6 +142,44 @@ void testjson()
int main( int argc, char *argv[] )
{
/*
if( argc < 2 ) {
std::cout << "parameter errors";
return 1;
}
std::string cmd = "ffmpeg -i ";
cmd += argv[1];
cmd += " 2>&1";
std::cout << "cmd:" << cmd << std::endl;
std::string result;
int d = myexec(cmd, result);
if(d != 0 )
{
std::cout << "open " << cmd << " failed";
return 1;
}
int nfind = result.find("rotate :");
if(nfind >= 0)
{
int nfind2 = result.find("\n", nfind + 17);
if (nfind2 >= 0)
{
std::cout << "rotate:" << result.substr(nfind + 17, nfind2 - nfind - 17) << std::endl;
int nr = atoi(result.substr(nfind+17, nfind2 - nfind - 17).c_str());
std::cout << "nr:" << nr << std::endl;
}
}else
{
std::cout << "----do not find rotate---" << std::endl;
}
std::cout << "----ok---" << std::endl;
//std::cout << result << std::endl;
return 0;
*/
//testjson();
//return 1;
/*
......
......@@ -15,7 +15,7 @@
#include <iostream>
#include <sstream>
#include <string.h>
#include <stdio.h>
std::string floattostring( float value )
{
......@@ -546,3 +546,23 @@ int parse_http_parameters( const std::string &body, std::map<std::string, std::s
return paramters.size();
}
int myexec(const std::string &cmd, std::string &result)
{
result = "" ;
FILE *pp = popen(cmd.c_str(), "r");
if (!pp) {
return -1;
}
char tmp[1024];
memset(tmp, 0, sizeof(tmp));
while (fgets(tmp, (sizeof(tmp) - 1), pp) != NULL) {
result += std::string(tmp);
//std::cout << "--myexec:" << result.length() << std::endl;
memset(tmp, 0, sizeof(tmp));
}
pclose(pp);
//std::cout << "myexec:" << result.length() << std::endl;
return 0;
}
......@@ -16,3 +16,17 @@ sudo docker run -t -d --rm --net host -p 4000:4000 -v /tmp/data:/data ygyd:1 ./
ffmpeg -t 20 -f v4l2 -i /dev/video0 -r 20 -f mp4 cap1.mp4
ffplay ./cap1.mp4
ygyd gpu server
47.92.209.161
root
yixinxd@2022^%
—————————
cpu server
IP:8.142.64.229
用户名:root
密码:yixinxd@2022^%
项目路径:/usr/local/zkyx」
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!