Commit 641cf4ba by wangquyuan

add by wqy

1 parent c866715e
......@@ -49,7 +49,7 @@ public:
//JSONField( self, MysqlConfig, db );
JSONField( self, int, frame_fps ) = 25;
//JSONField( self, int, frame_fps ) = 25;
JSONField( self, std::string, device ) = "cpu";
JSONField( self, ModelsConfig, models );
......
......@@ -39,10 +39,6 @@ Config *parse_config( const std::string &name )
return NULL;
}
if(config->frame_fps < 1)
{
config->frame_fps = 1;
}
return config;
}
......
......@@ -11,7 +11,8 @@ static std::vector<ErrorCode> errors =
{6, "database is not avilable"},
{7, "image data parse failed"},
{8, "open video failed"},
{9, "this pot is offline"},
{9, "parse multipart/form-data error"},
{10, "save upload file failed"},
};
......
......@@ -42,12 +42,14 @@ using websocketpp::lib::bind;
//typedef server::message_ptr message_ptr;
static std::string get_password() {
static std::string get_password()
{
return "test";
}
enum tls_mode {
enum tls_mode
{
MOZILLA_INTERMEDIATE = 1,
MOZILLA_MODERN = 2
};
......@@ -112,7 +114,7 @@ context_ptr on_tls_init(tls_mode mode, websocketpp::connection_hdl hdl) {
void testjson()
{
std::string strBody = "{";
strBody +="\"potuid\":\"P-ddc43fd6-c441-4d4d-9280-5f2bc2934390\",";
strBody += "\"potuid\":\"P-ddc43fd6-c441-4d4d-9280-5f2bc2934390\",";
strBody += "\"method\":\"post\",";
strBody += "\"url\":\"/pot/test\",";
strBody += "\"headers\":[";
......@@ -122,16 +124,16 @@ void testjson()
strBody += " \"max_face_size\":100";
strBody += " }}";
std::cout << strBody << std::endl;
orz::jug bjug = orz::json2jug(strBody);
orz::jug bjug = orz::json2jug( strBody );
orz::jug bodyjug = bjug["body"];
std::string strparam = orz::jug2json(bodyjug);
std::string strparam = orz::jug2json( bodyjug );
orz::DictPiece *piece = reinterpret_cast<orz::DictPiece *>( bjug.raw() );
if(piece)
if( piece )
{
piece->erase("body");
piece->erase( "body" );
}
std::string strdirect = orz::jug2json(bjug);
std::string strdirect = orz::jug2json( bjug );
strdirect = strdirect + strparam;
std::cout << strdirect << std::endl;
}
......@@ -180,16 +182,17 @@ int main( int argc, char *argv[] )
return -1;
}
//std::cout << "frame_fps:" << g_config->frame_fps << std::endl;
std::cout << "device:" << g_config->device << std::endl;
std::cout << "face_detector:" << g_config->models.face_detector << std::endl;
std::cout << "face_landmarker81:" << g_config->models.face_landmarker81 << std::endl;
std::cout << "face_landmarker5:" << g_config->models.face_landmarker5 << std::endl;
std::cout << "face_recognizer:" << g_config->models.face_recognizer<< std::endl;
std::cout << "face_recognizer:" << g_config->models.face_recognizer << std::endl;
std::cout << "pose_model:" << g_config->models.pose_model<< std::endl;
std::cout << "pose_model:" << g_config->models.pose_model << std::endl;
std::cout << "actionunit_model:" << g_config->models.actionunit_model << std::endl;
std::cout << "emotion_model:" << g_config->models.emotion_model<< std::endl;
std::cout << "eye_model:" << g_config->models.eye_model<< std::endl;
std::cout << "emotion_model:" << g_config->models.emotion_model << std::endl;
std::cout << "eye_model:" << g_config->models.eye_model << std::endl;
......@@ -224,10 +227,10 @@ int main( int argc, char *argv[] )
if (init_engine() < 0 )
if( init_engine() < 0 )
{
std::cout << "init engine failed, system exited!" << std::endl;
LOG(_ERROR_, "init engine failed, system exited");
LOG( _ERROR_, "init engine failed, system exited" );
return -1;
}
/*
......@@ -289,6 +292,8 @@ int main( int argc, char *argv[] )
bone_server.set_listen_backlog( 8192 );
bone_server.listen( g_config->http_port );
bone_server.set_max_http_body_size(1024 * 1024 * 2000);
std::cout << "init http max_body_size:" << bone_server.get_max_http_body_size() << std::endl;
std::cout << "init max_message_size:" << bone_server.get_max_message_size() << std::endl;
std::cout << "http port:" << g_config->http_port << std::endl;
//bone_server.set_max_message_size(96000000);
......
......@@ -2,12 +2,12 @@
#include "simplelog.h"
#ifdef _WIN32
#include <windows.h>
#include <windows.h>
#else
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#endif
#include <openssl/md5.h>
......@@ -17,12 +17,12 @@
#include <string.h>
std::string floattostring(float value)
std::string floattostring( float value )
{
char buf[100];
memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "%0.2f", value);
return std::string(buf);
memset( buf, 0, sizeof( buf ) );
snprintf( buf, sizeof( buf ) - 1, "%0.2f", value );
return std::string( buf );
}
......@@ -372,30 +372,30 @@ std::string decodeuricomponent( const std::string &str )
int checkinstance()
{
std::string exepath,exename;
std::string exepath, exename;
GetExePathAndName( exepath, exename );
//std::string str = exepath + exename;
std::string str = exepath + ".";
str += exename + "_lock";
#ifdef _WIN32
HANDLE hfile = CreateFileA(str.c_str(), FILE_GENERIC_READ|FILE_GENERIC_WRITE,0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL);
if(hfile)
#ifdef _WIN32
HANDLE hfile = CreateFileA( str.c_str(), FILE_GENERIC_READ | FILE_GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
if( hfile )
{
if(LocfFile(hfile, 0,0,0,0))
if( LocfFile( hfile, 0, 0, 0, 0 ) )
{
return 0;
}
CloseHandle(hfile);
CloseHandle( hfile );
}
return -1;
#else
int fd = open(str.c_str(), O_CREAT|O_RDWR, 0666);
if(fd < 0)
#else
int fd = open( str.c_str(), O_CREAT | O_RDWR, 0666 );
if( fd < 0 )
{
std::cout << "error:" << strerror(errno) << std::endl;
std::cout << "error:" << strerror( errno ) << std::endl;
return -1;
}
......@@ -405,52 +405,53 @@ int checkinstance()
lock.l_whence = 0;
lock.l_len = 0;
if(fcntl(fd, F_SETLK, &lock) < 0)
if( fcntl( fd, F_SETLK, &lock ) < 0 )
{
std::cout << "fntl error:" << strerror(errno) << std::endl;
close(fd);
std::cout << "fntl error:" << strerror( errno ) << std::endl;
close( fd );
return -1;
}
#endif
#endif
return 0;
}
void geturlparameters(const std::string &str, std::map<std::string, std::string> &params)
void geturlparameters( const std::string &str, std::map<std::string, std::string> &params )
{
std::string strtmp;
std::vector<std::string> vecs;
splits(str, "&", vecs);
splits( str, "&", vecs );
int offset = 0;
for(int i=0; i<vecs.size(); i++)
for( int i = 0; i < vecs.size(); i++ )
{
strtmp = vecs[i];
offset = strtmp.find("=");
if(offset <= 0)
offset = strtmp.find( "=" );
if( offset <= 0 )
{
continue;
}
std::string key = strtmp.substr(0, offset);
key = trim(key);
key = decodeuricomponent(key);
std::string value = strtmp.substr(offset + 1);
value = trim(value);
value = decodeuricomponent(value);
if((key.length() < 1)|| (value.length() < 1))
std::string key = strtmp.substr( 0, offset );
key = trim( key );
key = decodeuricomponent( key );
std::string value = strtmp.substr( offset + 1 );
value = trim( value );
value = decodeuricomponent( value );
if( ( key.length() < 1 ) || ( value.length() < 1 ) )
{
continue;
}
std::cout << "key:" << key << ", value:" << value << std::endl;
params.insert(std::map<std::string, std::string>::value_type(key, value));
params.insert( std::map<std::string, std::string>::value_type( key, value ) );
}
}
std::string encodetojson(const std::string &str)
std::string encodetojson( const std::string &str )
{
std::ostringstream oss;
static const std::map<char, std::string> escape = {
static const std::map<char, std::string> escape =
{
{'\"', R"(\")"},
{'\\', R"(\\)"},
{'/', R"(/)"},
......@@ -460,13 +461,14 @@ std::string encodetojson(const std::string &str)
{'\r', R"(\r)"},
{'\t', R"(\t)"},
};
for (auto &ch : str)
for( auto &ch : str )
{
auto it = escape.find(ch);
if (it != escape.end())
auto it = escape.find( ch );
if( it != escape.end() )
{
oss << it->second;
} else
}
else
{
oss << ch;
}
......@@ -475,65 +477,66 @@ std::string encodetojson(const std::string &str)
}
bool is_space_char(unsigned char c)
bool is_space_char( unsigned char c )
{
return (c == 9 || c == 32);
return ( c == 9 || c == 32 );
}
int skip_space_chars(const std::string &str, std::string::size_type nbegin)
int skip_space_chars( const std::string &str, std::string::size_type nbegin )
{
while(is_space_char(str[nbegin]))
while( is_space_char( str[nbegin] ) )
{
if(nbegin >= str.length() - 1)
if( nbegin >= str.length() - 1 )
return nbegin;
nbegin++;
}
return nbegin;
}
static int parse_paramter(const std::string &str, std::string &name, std::string &value)
static int parse_paramter( const std::string &str, std::string &name, std::string &value )
{
std::string::size_type nfind = str.find("=");
if(nfind != std::string::npos)
std::string::size_type nfind = str.find( "=" );
if( nfind != std::string::npos )
{
name = str.substr(0, nfind);
value = str.substr(nfind + 1);
name = decodeuricomponent(name);//urldecode(name);
value = decodeuricomponent(value);//urldecode(value);
name = str.substr( 0, nfind );
value = str.substr( nfind + 1 );
name = decodeuricomponent( name ); //urldecode(name);
value = decodeuricomponent( value ); //urldecode(value);
return 0;
}
return -1;
}
int parse_http_parameters(const std::string & body, std::map<std::string,std::string> &paramters)
int parse_http_parameters( const std::string &body, std::map<std::string, std::string> &paramters )
{
//LOG(_INFO_,"recv post req:%s ",GETNULLSTR(command));
std::string::size_type nbegin,nend, nfind;
std::string::size_type nbegin, nend, nfind;
nbegin = nend = 0;
nbegin = skip_space_chars(body, 0);
std::string name,value;
nbegin = skip_space_chars( body, 0 );
std::string name, value;
std::string strtmp;
//std::map<std::string, std::string> paramters;
while(1)
while( 1 )
{
name = value = "";
nfind = body.find("&", nbegin);
if(nfind != std::string::npos)
nfind = body.find( "&", nbegin );
if( nfind != std::string::npos )
{
strtmp = body.substr(nbegin, nfind - nbegin);
if(parse_paramter(strtmp, name, value) >= 0)
strtmp = body.substr( nbegin, nfind - nbegin );
if( parse_paramter( strtmp, name, value ) >= 0 )
{
paramters[name] = value;
}
nbegin = nfind + 1;
continue;
}else if(nbegin < body.length())
}
else if( nbegin < body.length() )
{
strtmp = body.substr(nbegin);
if(parse_paramter(strtmp, name, value) >= 0)
strtmp = body.substr( nbegin );
if( parse_paramter( strtmp, name, value ) >= 0 )
{
paramters[name] = value;
}
......
......@@ -9,13 +9,17 @@ import (
//"sync"
"encoding/json"
//"strconv"
//"time"
"time"
//"math/rand"
//"crypto/md5"
//"bytes"
//"os"
"bytes"
"os"
"io"
"mime/multipart"
"encoding/base64"
"flag"
"path/filepath"
//"bufio"
)
......@@ -237,6 +241,225 @@ func get_emotion(filename, url string) bool {
return true
}
func get_video(filename, url string) bool {
//data := `{"check_id":"sJjcUq2CORH8tTjSNJ14","check_code":"97369"}`
//str := sign(data)
data1, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println("read file failed: ", err.Error())
return false
}
strdata := base64.StdEncoding.EncodeToString(data1)
data := "userVideo=" + strdata
data += "&frameNum=10"
//seq := "http://192.168.1.33:4000/query/feature"
seq := url + "/query/video"
client := &http.Client{}
request, err := http.NewRequest("POST", seq, strings.NewReader(data))
if err != nil {
fmt.Println("create request failed: " , err)
return false
}
//resp, err := http.Post(seq, "application/x-www-form-urlencoded",
// strings.NewReader(data))
//if err != nil {
// fmt.Println("send request error: " , err)
// return false
//}
//request.Header.Add("Authorization","AIPSS1.0 " + str)
//request.Header.Add("Content-Type","application/json; charset=utf-8")
request.Header.Add("Content-Type","application/x-www-form-urlencoded")
resp, err := client.Do(request)
if err != nil {
fmt.Println("send error: " , err)
return false
}else {
fmt.Println("send ok")
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("LoginSeetaAuthCenter ReadAll failed: ", err)
return false
}else {
fmt.Println("length:", len(body))
}
fmt.Println(string(body))
/*
var res Response2
err = json.Unmarshal(body, &res)
if err != nil {
fmt.Println("Unmarshal error:", err)
return false
}
if res.Code == 0 {
fmt.Println("face detector ok" )
//bits := base64.StdEncoding.DecodeToString(res.Data)
fmt.Println(res)
}else {
fmt.Println("face detector falied" )
}
*/
return true
}
func get_video2(filename, url string) bool {
//data := `{"check_id":"sJjcUq2CORH8tTjSNJ14","check_code":"97369"}`
//str := sign(data)
file, err := os.Open(filename)
if err != nil {
fmt.Println("open file failed,", err)
return false
}
defer file.Close()
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("file", filepath.Base(filename))
if err != nil {
fmt.Println("create form file failed", err)
return false
}
_, err = io.Copy(part, file)
writer.WriteField("frameNum", "100")
err = writer.Close()
if err != nil {
fmt.Println("writer Close failed", err)
return false
}
/*
data1, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println("read file failed: ", err.Error())
return false
}
strdata := base64.StdEncoding.EncodeToString(data1)
data := "userVideo=" + strdata
data += "&frameNum=10"
*/
//seq := "http://192.168.1.33:4000/query/feature"
seq := url + "/query/video"
client := &http.Client{Timeout: 60 * time.Second,}
request, err := http.NewRequest("POST", seq, body)
if err != nil {
fmt.Println("new request failed", err)
return false
}
//resp, err := http.Post(seq, "application/x-www-form-urlencoded",
// strings.NewReader(data))
//if err != nil {
// fmt.Println("send request error: " , err)
// return false
//}
//request.Header.Add("Authorization","AIPSS1.0 " + str)
//request.Header.Add("Content-Type","application/json; charset=utf-8")
request.Header.Add("Content-Type",writer.FormDataContentType())
resp, err := client.Do(request)
if err != nil {
fmt.Println("send error: " , err)
return false
}else {
fmt.Println("send ok")
}
defer resp.Body.Close()
/*
var body2 string
var d = 0
r := bufio.NewReader(resp.Body)
block := make([]byte, 1024)
for {
n,err := r.Read(block)
if err != nil && err != io.EOF {
fmt.Println("recv ReadAll failed: ", err)
return false
}
d += n
fmt.Println("read:",d)
if n == 0 {
break
}else {
body2 += string(block[0:n])
}
}
*/
//body2, err := ioutil.ReadAll(io.LimitReader(resp.Body, int64(3<<20)))
body2, err := io.ReadAll(resp.Body)
if err != nil {
if strings.Contains(err.Error(), "unexpected EOF") && len(body2) > 0 {
}else {
fmt.Println("recv ReadAll failed: ", err)
return false
}
}else {
fmt.Println("length:", len(body2))
}
fmt.Println("length:", len(body2))
//fmt.Println(string(body2))
ioutil.WriteFile("/tmp/recv.txt",body2, 0666);
/*
var res Response2
err = json.Unmarshal(body, &res)
if err != nil {
fmt.Println("Unmarshal error:", err)
return false
}
if res.Code == 0 {
fmt.Println("face detector ok" )
//bits := base64.StdEncoding.DecodeToString(res.Data)
fmt.Println(res)
}else {
fmt.Println("face detector falied" )
}
*/
return true
}
var gname string
......@@ -262,6 +485,8 @@ func main() {
get_action(gfilename, gurl)
}else if gname == "emotion" {
get_emotion(gfilename, gurl)
}else if gname == "video" {
get_video2(gfilename, gurl)
}else {
fmt.Println("not support type:",gname)
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!