Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wangquyuan
/
ygydserver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 641cf4ba
authored
Aug 19, 2022
by
wangquyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add by wqy
1 parent
c866715e
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
319 additions
and
89 deletions
src/include/config.h
src/src/config.cpp
src/src/do_request.cpp
src/src/errorcode.cpp
src/src/server.cpp
src/src/util.cpp
test/test.go
src/include/config.h
View file @
641cf4b
...
@@ -49,7 +49,7 @@ public:
...
@@ -49,7 +49,7 @@ public:
//JSONField( self, MysqlConfig, db );
//JSONField( self, MysqlConfig, db );
JSONField
(
self
,
int
,
frame_fps
)
=
25
;
//
JSONField( self, int, frame_fps ) = 25;
JSONField
(
self
,
std
::
string
,
device
)
=
"cpu"
;
JSONField
(
self
,
std
::
string
,
device
)
=
"cpu"
;
JSONField
(
self
,
ModelsConfig
,
models
);
JSONField
(
self
,
ModelsConfig
,
models
);
...
...
src/src/config.cpp
View file @
641cf4b
...
@@ -39,10 +39,6 @@ Config *parse_config( const std::string &name )
...
@@ -39,10 +39,6 @@ Config *parse_config( const std::string &name )
return
NULL
;
return
NULL
;
}
}
if
(
config
->
frame_fps
<
1
)
{
config
->
frame_fps
=
1
;
}
return
config
;
return
config
;
}
}
...
...
src/src/do_request.cpp
View file @
641cf4b
This diff is collapsed.
Click to expand it.
src/src/errorcode.cpp
View file @
641cf4b
...
@@ -11,7 +11,8 @@ static std::vector<ErrorCode> errors =
...
@@ -11,7 +11,8 @@ static std::vector<ErrorCode> errors =
{
6
,
"database is not avilable"
},
{
6
,
"database is not avilable"
},
{
7
,
"image data parse failed"
},
{
7
,
"image data parse failed"
},
{
8
,
"open video failed"
},
{
8
,
"open video failed"
},
{
9
,
"this pot is offline"
},
{
9
,
"parse multipart/form-data error"
},
{
10
,
"save upload file failed"
},
};
};
...
...
src/src/server.cpp
View file @
641cf4b
...
@@ -42,12 +42,14 @@ using websocketpp::lib::bind;
...
@@ -42,12 +42,14 @@ using websocketpp::lib::bind;
//typedef server::message_ptr message_ptr;
//typedef server::message_ptr message_ptr;
static
std
::
string
get_password
()
{
static
std
::
string
get_password
()
{
return
"test"
;
return
"test"
;
}
}
enum
tls_mode
{
enum
tls_mode
{
MOZILLA_INTERMEDIATE
=
1
,
MOZILLA_INTERMEDIATE
=
1
,
MOZILLA_MODERN
=
2
MOZILLA_MODERN
=
2
};
};
...
@@ -112,7 +114,7 @@ context_ptr on_tls_init(tls_mode mode, websocketpp::connection_hdl hdl) {
...
@@ -112,7 +114,7 @@ context_ptr on_tls_init(tls_mode mode, websocketpp::connection_hdl hdl) {
void
testjson
()
void
testjson
()
{
{
std
::
string
strBody
=
"{"
;
std
::
string
strBody
=
"{"
;
strBody
+=
"
\"
potuid
\"
:
\"
P-ddc43fd6-c441-4d4d-9280-5f2bc2934390
\"
,"
;
strBody
+=
"
\"
potuid
\"
:
\"
P-ddc43fd6-c441-4d4d-9280-5f2bc2934390
\"
,"
;
strBody
+=
"
\"
method
\"
:
\"
post
\"
,"
;
strBody
+=
"
\"
method
\"
:
\"
post
\"
,"
;
strBody
+=
"
\"
url
\"
:
\"
/pot/test
\"
,"
;
strBody
+=
"
\"
url
\"
:
\"
/pot/test
\"
,"
;
strBody
+=
"
\"
headers
\"
:["
;
strBody
+=
"
\"
headers
\"
:["
;
...
@@ -122,16 +124,16 @@ void testjson()
...
@@ -122,16 +124,16 @@ void testjson()
strBody
+=
"
\"
max_face_size
\"
:100"
;
strBody
+=
"
\"
max_face_size
\"
:100"
;
strBody
+=
" }}"
;
strBody
+=
" }}"
;
std
::
cout
<<
strBody
<<
std
::
endl
;
std
::
cout
<<
strBody
<<
std
::
endl
;
orz
::
jug
bjug
=
orz
::
json2jug
(
strBody
);
orz
::
jug
bjug
=
orz
::
json2jug
(
strBody
);
orz
::
jug
bodyjug
=
bjug
[
"body"
];
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
()
);
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
;
strdirect
=
strdirect
+
strparam
;
std
::
cout
<<
strdirect
<<
std
::
endl
;
std
::
cout
<<
strdirect
<<
std
::
endl
;
}
}
...
@@ -180,16 +182,17 @@ int main( int argc, char *argv[] )
...
@@ -180,16 +182,17 @@ int main( int argc, char *argv[] )
return
-
1
;
return
-
1
;
}
}
//std::cout << "frame_fps:" << g_config->frame_fps << std::endl;
std
::
cout
<<
"device:"
<<
g_config
->
device
<<
std
::
endl
;
std
::
cout
<<
"device:"
<<
g_config
->
device
<<
std
::
endl
;
std
::
cout
<<
"face_detector:"
<<
g_config
->
models
.
face_detector
<<
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_landmarker81:"
<<
g_config
->
models
.
face_landmarker81
<<
std
::
endl
;
std
::
cout
<<
"face_landmarker5:"
<<
g_config
->
models
.
face_landmarker5
<<
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
<<
"actionunit_model:"
<<
g_config
->
models
.
actionunit_model
<<
std
::
endl
;
std
::
cout
<<
"emotion_model:"
<<
g_config
->
models
.
emotion_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
<<
"eye_model:"
<<
g_config
->
models
.
eye_model
<<
std
::
endl
;
...
@@ -224,10 +227,10 @@ int main( int argc, char *argv[] )
...
@@ -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
;
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
;
return
-
1
;
}
}
/*
/*
...
@@ -289,6 +292,8 @@ int main( int argc, char *argv[] )
...
@@ -289,6 +292,8 @@ int main( int argc, char *argv[] )
bone_server
.
set_listen_backlog
(
8192
);
bone_server
.
set_listen_backlog
(
8192
);
bone_server
.
listen
(
g_config
->
http_port
);
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
<<
"init max_message_size:"
<<
bone_server
.
get_max_message_size
()
<<
std
::
endl
;
std
::
cout
<<
"http port:"
<<
g_config
->
http_port
<<
std
::
endl
;
std
::
cout
<<
"http port:"
<<
g_config
->
http_port
<<
std
::
endl
;
//bone_server.set_max_message_size(96000000);
//bone_server.set_max_message_size(96000000);
...
...
src/src/util.cpp
View file @
641cf4b
...
@@ -2,12 +2,12 @@
...
@@ -2,12 +2,12 @@
#include "simplelog.h"
#include "simplelog.h"
#ifdef _WIN32
#ifdef _WIN32
#include <windows.h>
#include <windows.h>
#else
#else
#include <fcntl.h>
#include <fcntl.h>
#include <unistd.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#endif
#endif
#include <openssl/md5.h>
#include <openssl/md5.h>
...
@@ -17,12 +17,12 @@
...
@@ -17,12 +17,12 @@
#include <string.h>
#include <string.h>
std
::
string
floattostring
(
float
value
)
std
::
string
floattostring
(
float
value
)
{
{
char
buf
[
100
];
char
buf
[
100
];
memset
(
buf
,
0
,
sizeof
(
buf
)
);
memset
(
buf
,
0
,
sizeof
(
buf
)
);
snprintf
(
buf
,
sizeof
(
buf
)
-
1
,
"%0.2f"
,
value
);
snprintf
(
buf
,
sizeof
(
buf
)
-
1
,
"%0.2f"
,
value
);
return
std
::
string
(
buf
);
return
std
::
string
(
buf
);
}
}
...
@@ -372,30 +372,30 @@ std::string decodeuricomponent( const std::string &str )
...
@@ -372,30 +372,30 @@ std::string decodeuricomponent( const std::string &str )
int
checkinstance
()
int
checkinstance
()
{
{
std
::
string
exepath
,
exename
;
std
::
string
exepath
,
exename
;
GetExePathAndName
(
exepath
,
exename
);
GetExePathAndName
(
exepath
,
exename
);
//std::string str = exepath + exename;
//std::string str = exepath + exename;
std
::
string
str
=
exepath
+
"."
;
std
::
string
str
=
exepath
+
"."
;
str
+=
exename
+
"_lock"
;
str
+=
exename
+
"_lock"
;
#ifdef _WIN32
#ifdef _WIN32
HANDLE
hfile
=
CreateFileA
(
str
.
c_str
(),
FILE_GENERIC_READ
|
FILE_GENERIC_WRITE
,
0
,
NULL
,
CREATE_ALWAYS
,
FILE_ATTRIBUTE_NORMAL
,
NULL
);
HANDLE
hfile
=
CreateFileA
(
str
.
c_str
(),
FILE_GENERIC_READ
|
FILE_GENERIC_WRITE
,
0
,
NULL
,
CREATE_ALWAYS
,
FILE_ATTRIBUTE_NORMAL
,
NULL
);
if
(
hfile
)
if
(
hfile
)
{
{
if
(
LocfFile
(
hfile
,
0
,
0
,
0
,
0
)
)
if
(
LocfFile
(
hfile
,
0
,
0
,
0
,
0
)
)
{
{
return
0
;
return
0
;
}
}
CloseHandle
(
hfile
);
CloseHandle
(
hfile
);
}
}
return
-
1
;
return
-
1
;
#else
#else
int
fd
=
open
(
str
.
c_str
(),
O_CREAT
|
O_RDWR
,
0666
);
int
fd
=
open
(
str
.
c_str
(),
O_CREAT
|
O_RDWR
,
0666
);
if
(
fd
<
0
)
if
(
fd
<
0
)
{
{
std
::
cout
<<
"error:"
<<
strerror
(
errno
)
<<
std
::
endl
;
std
::
cout
<<
"error:"
<<
strerror
(
errno
)
<<
std
::
endl
;
return
-
1
;
return
-
1
;
}
}
...
@@ -405,52 +405,53 @@ int checkinstance()
...
@@ -405,52 +405,53 @@ int checkinstance()
lock
.
l_whence
=
0
;
lock
.
l_whence
=
0
;
lock
.
l_len
=
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
;
std
::
cout
<<
"fntl error:"
<<
strerror
(
errno
)
<<
std
::
endl
;
close
(
fd
);
close
(
fd
);
return
-
1
;
return
-
1
;
}
}
#endif
#endif
return
0
;
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
::
string
strtmp
;
std
::
vector
<
std
::
string
>
vecs
;
std
::
vector
<
std
::
string
>
vecs
;
splits
(
str
,
"&"
,
vecs
);
splits
(
str
,
"&"
,
vecs
);
int
offset
=
0
;
int
offset
=
0
;
for
(
int
i
=
0
;
i
<
vecs
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
vecs
.
size
();
i
++
)
{
{
strtmp
=
vecs
[
i
];
strtmp
=
vecs
[
i
];
offset
=
strtmp
.
find
(
"="
);
offset
=
strtmp
.
find
(
"="
);
if
(
offset
<=
0
)
if
(
offset
<=
0
)
{
{
continue
;
continue
;
}
}
std
::
string
key
=
strtmp
.
substr
(
0
,
offset
);
std
::
string
key
=
strtmp
.
substr
(
0
,
offset
);
key
=
trim
(
key
);
key
=
trim
(
key
);
key
=
decodeuricomponent
(
key
);
key
=
decodeuricomponent
(
key
);
std
::
string
value
=
strtmp
.
substr
(
offset
+
1
);
std
::
string
value
=
strtmp
.
substr
(
offset
+
1
);
value
=
trim
(
value
);
value
=
trim
(
value
);
value
=
decodeuricomponent
(
value
);
value
=
decodeuricomponent
(
value
);
if
(
(
key
.
length
()
<
1
)
||
(
value
.
length
()
<
1
)
)
if
(
(
key
.
length
()
<
1
)
||
(
value
.
length
()
<
1
)
)
{
{
continue
;
continue
;
}
}
std
::
cout
<<
"key:"
<<
key
<<
", value:"
<<
value
<<
std
::
endl
;
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
;
std
::
ostringstream
oss
;
static
const
std
::
map
<
char
,
std
::
string
>
escape
=
{
static
const
std
::
map
<
char
,
std
::
string
>
escape
=
{
{
'\"'
,
R"(\")"
},
{
'\"'
,
R"(\")"
},
{
'\\'
,
R"(\\)"
},
{
'\\'
,
R"(\\)"
},
{
'/'
,
R"(/)"
},
{
'/'
,
R"(/)"
},
...
@@ -460,13 +461,14 @@ std::string encodetojson(const std::string &str)
...
@@ -460,13 +461,14 @@ std::string encodetojson(const std::string &str)
{
'\r'
,
R"(\r)"
},
{
'\r'
,
R"(\r)"
},
{
'\t'
,
R"(\t)"
},
{
'\t'
,
R"(\t)"
},
};
};
for
(
auto
&
ch
:
str
)
for
(
auto
&
ch
:
str
)
{
{
auto
it
=
escape
.
find
(
ch
);
auto
it
=
escape
.
find
(
ch
);
if
(
it
!=
escape
.
end
()
)
if
(
it
!=
escape
.
end
()
)
{
{
oss
<<
it
->
second
;
oss
<<
it
->
second
;
}
else
}
else
{
{
oss
<<
ch
;
oss
<<
ch
;
}
}
...
@@ -475,65 +477,66 @@ std::string encodetojson(const std::string &str)
...
@@ -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
;
return
nbegin
;
nbegin
++
;
nbegin
++
;
}
}
return
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
(
"="
);
std
::
string
::
size_type
nfind
=
str
.
find
(
"="
);
if
(
nfind
!=
std
::
string
::
npos
)
if
(
nfind
!=
std
::
string
::
npos
)
{
{
name
=
str
.
substr
(
0
,
nfind
);
name
=
str
.
substr
(
0
,
nfind
);
value
=
str
.
substr
(
nfind
+
1
);
value
=
str
.
substr
(
nfind
+
1
);
name
=
decodeuricomponent
(
name
);
//urldecode(name);
name
=
decodeuricomponent
(
name
);
//urldecode(name);
value
=
decodeuricomponent
(
value
);
//urldecode(value);
value
=
decodeuricomponent
(
value
);
//urldecode(value);
return
0
;
return
0
;
}
}
return
-
1
;
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));
//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
=
nend
=
0
;
nbegin
=
skip_space_chars
(
body
,
0
);
nbegin
=
skip_space_chars
(
body
,
0
);
std
::
string
name
,
value
;
std
::
string
name
,
value
;
std
::
string
strtmp
;
std
::
string
strtmp
;
//std::map<std::string, std::string> paramters;
//std::map<std::string, std::string> paramters;
while
(
1
)
while
(
1
)
{
{
name
=
value
=
""
;
name
=
value
=
""
;
nfind
=
body
.
find
(
"&"
,
nbegin
);
nfind
=
body
.
find
(
"&"
,
nbegin
);
if
(
nfind
!=
std
::
string
::
npos
)
if
(
nfind
!=
std
::
string
::
npos
)
{
{
strtmp
=
body
.
substr
(
nbegin
,
nfind
-
nbegin
);
strtmp
=
body
.
substr
(
nbegin
,
nfind
-
nbegin
);
if
(
parse_paramter
(
strtmp
,
name
,
value
)
>=
0
)
if
(
parse_paramter
(
strtmp
,
name
,
value
)
>=
0
)
{
{
paramters
[
name
]
=
value
;
paramters
[
name
]
=
value
;
}
}
nbegin
=
nfind
+
1
;
nbegin
=
nfind
+
1
;
continue
;
continue
;
}
else
if
(
nbegin
<
body
.
length
())
}
else
if
(
nbegin
<
body
.
length
()
)
{
{
strtmp
=
body
.
substr
(
nbegin
);
strtmp
=
body
.
substr
(
nbegin
);
if
(
parse_paramter
(
strtmp
,
name
,
value
)
>=
0
)
if
(
parse_paramter
(
strtmp
,
name
,
value
)
>=
0
)
{
{
paramters
[
name
]
=
value
;
paramters
[
name
]
=
value
;
}
}
...
...
test/test.go
View file @
641cf4b
...
@@ -9,13 +9,17 @@ import (
...
@@ -9,13 +9,17 @@ import (
//"sync"
//"sync"
"encoding/json"
"encoding/json"
//"strconv"
//"strconv"
//
"time"
"time"
//"math/rand"
//"math/rand"
//"crypto/md5"
//"crypto/md5"
//"bytes"
"bytes"
//"os"
"os"
"io"
"mime/multipart"
"encoding/base64"
"encoding/base64"
"flag"
"flag"
"path/filepath"
//"bufio"
)
)
...
@@ -237,6 +241,225 @@ func get_emotion(filename, url string) bool {
...
@@ -237,6 +241,225 @@ func get_emotion(filename, url string) bool {
return
true
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
var
gname
string
...
@@ -262,6 +485,8 @@ func main() {
...
@@ -262,6 +485,8 @@ func main() {
get_action
(
gfilename
,
gurl
)
get_action
(
gfilename
,
gurl
)
}
else
if
gname
==
"emotion"
{
}
else
if
gname
==
"emotion"
{
get_emotion
(
gfilename
,
gurl
)
get_emotion
(
gfilename
,
gurl
)
}
else
if
gname
==
"video"
{
get_video2
(
gfilename
,
gurl
)
}
else
{
}
else
{
fmt
.
Println
(
"not support type:"
,
gname
)
fmt
.
Println
(
"not support type:"
,
gname
)
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment