赞
踩
本次使用的人脸识别平台为翔云平台
购买连接为:https://www.netocr.com/order/price.html
//https://www.openssl.org/source/
//https://ftp.openssl.org/source/old/1.1.1
wget https://ftp.openssl.org/source/old/1.1.1/openssl-1.1.1i.tar.gz
tar -xzf openssl-1.1.1i.tar.gz
cd openssl-1.1.1i/
./config
make -j4
sudo make install
//https://github.com/curl/curl/releases/tag/curl-7_71_1
wget https://curl.se/download/curl-7.71.1.tar.bz2
tar -xjf curl-7.71.1.tar.bz2
cd curl-7.71.1/
./configure --prefix=$HOME/curl --with-ssl
make -j4
make install
export LD_LIBRARY_PATH=./curl-7.71.1/_install/lib/
或
export C_INCLUDE_PATH=$C_INCLUDE_PATH:$HOME/curl/include
export LIBRARY_PATH=$LIBRARY_PATH:$HOME/curl/lib
执行以下命令生效
sudo vi /etc/profile
打开文件后添加
export C_INCLUDE_PATH=$C_INCLUDE_PATH:$HOME/curl/include
export LIBRARY_PATH=$LIBRARY_PATH:$HOME/curl/lib
改写完生效一下
source /etc/profile
此图为我们上传所需参数
#include <stdio.h> #include <curl/curl.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #define true 1 #define false 0 typedef unsigned int bool; size_t readData( void *ptr, size_t size,size_t nmemb, void *stream) { char buf[10240] = {'\0'}; strncpy(buf,ptr,10240); if(strstr(buf,"是") != 0){ printf("yes"); }else{ printf("no"); } } char *getBase64FromPic(char * filePath) { char cmd[124] ={'\0'}; sprintf(cmd,"base64 %s >tmpfile",filePath); system(cmd); int fd; int length; fd = open("./tmpfile",O_RDWR); length = lseek(fd,0,SEEK_END); char *img2buf = (char *)malloc(length+8); memset(img2buf,0,length+8); lseek(fd,0,SEEK_SET); read(fd,img2buf,length); close(fd); system("rm tmpfile"); return img2buf; } bool postUrl(char *filename) { CURL *curl; CURLcode res; char *img1; char *img2; char *key = "写上你买来的key"; char *secret = "写上你买来的secret"; int typeId = 21; char *format = "xml"; img1 = getBase64FromPic("liu1.jpeg"); img2 = getBase64FromPic("liu2.jpeg"); char *postString; int len = strlen(key)+ strlen(secret)+ strlen(img1)+ strlen(img2)+ 1024; postString = (char *)malloc(len); memset(postString,0, len); sprintf(postString,"&img1=%s&img2=%s&key=%s&secret=%s&typeId=%d&format=%s",img1,img2,key,secret,21,format); curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); // 指定cookie文件 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postString); // 指定post内容 //curl_easy_setopt(curl, CURLOPT_PROXY, "10.99.60.201:8080"); curl_easy_setopt(curl, CURLOPT_URL, "https://netocr.com/api/faceliu.do"); // 指定url curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, readData); //将返回的http头输出到fp指向的文件 res = curl_easy_perform(curl); curl_easy_cleanup(curl); } return true; } int main(void) { postUrl("/tmp/post.html"); }
编译
gcc demo7.c -I ./curl-7.71.1/_install/include/ -L ./curl-7.71.1/_install/lib/ -lcurl -o demo7
连接上刚才解压的curl库
vi start.sh
红色那句修改为
./mjpg_streamer -i “./input_raspicam.so” -o “./output_http.so -w ./www”
运行 ./start.h即可运行
或
用绝对路径运行
/usr/local/bin/mjpg_streamer -i “/usr/local/lib/mjpg-streamer/input_uvc.so -n -f 30 -r 1280x720” -o “/usr/local/lib/mjpg-streamer/output_http.so -p 8080 -w /usr/local/share/mjpg-streamer/www”
system("raspistill -o file2.jpg");
浏览器输入 http://ip:8080
ip为树莓派ip地址
system("wget http://192.168.xxx.xxx:8080/?action=snapshot -q -O /home/pi/xxx.jpg")
system("/usr/local/bin/mjpg_streamer -i \"/usr/local/lib/mjpg-streamer/input_uvc.so -n -f 30 -r 1280x720\" -o \"/usr/local/lib/mjpg-streamer/output_http.so -p 8080 -w /usr/local/share/mjpg-streamer/www\" &")
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>-8产品类型错误
这是由于source insight 上的编码格式为gb2310 树莓派上的编码为utf-8 造成的
file->reload as encode 里面修改完重新写一下程序即可
/curl-7.71.1/_install/lib//libcurl.so: undefined reference to `SSL_CTX_set_keylog_callback@OPENSSL_1_1_1'
./curl-7.71.1/_install/lib//libcurl.so: undefined reference to `SSL_CTX_set_post_handshake_auth@OPENSSL_1_1_1'
./curl-7.71.1/_install/lib//libcurl.so: undefined reference to `SSL_CTX_set_ciphersuites@OPENSSL_1_1_1'
多加上这个连接
-lssl -lcrypto
openssl: /usr/lib/x86_64-linux-gnu/libssl.so.1.1: version OPENSSL_1_1_1’ not found (required by openssl)
这种情况是LD_LIBRARY_PATH这个环境变量没有指定。
解决方法:$ export LD_LIBRARY_PATH=/usr/local/lib
#include <stdio.h> #include <curl/curl.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <wiringPi.h> #define true 1 #define false 0 typedef unsigned int bool; int flag=2; size_t readData( void *ptr, size_t size,size_t nmemb, void *stream) { char buf[10240] = {'\0'}; strncpy(buf,ptr,10240); if(strstr(buf,"是") != 0){ flag=1; }else{ flag=0; } printf("%d\n",flag); } char *getBase64FromPic(char * filePath) { char cmd[124] ={'\0'}; sprintf(cmd,"base64 %s >tmpfile",filePath); system(cmd); int fd; int length; fd = open("./tmpfile",O_RDWR); length = lseek(fd,0,SEEK_END); char *img2buf = (char *)malloc(length+8); memset(img2buf,0,length+8); lseek(fd,0,SEEK_SET); read(fd,img2buf,length); close(fd); system("rm tmpfile"); return img2buf; } bool postUrl(char *filename) { CURL *curl; CURLcode res; char *img1; char *img2; char *key = ""; char *secret = ""; int typeId = 21; char *format = "xml"; img1 = getBase64FromPic("file1.jpg"); img2 = getBase64FromPic("liu2.jpeg"); char *postString; int len = strlen(key)+ strlen(secret)+ strlen(img1)+ strlen(img2)+ 1024; postString = (char *)malloc(len); memset(postString,0, len); sprintf(postString,"&img1=%s&img2=%s&key=%s&secret=%s&typeId=%d&format=%s",img1,img2,key,secret,21,format); curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); // 指定cookie文件 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postString); // 指定post内容 //curl_easy_setopt(curl, CURLOPT_PROXY, "10.99.60.201:8080"); curl_easy_setopt(curl, CURLOPT_URL, "https://netocr.com/api/faceliu.do"); // 指定url curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, readData); //将返回的http头输出到fp指向的文件 res = curl_easy_perform(curl); curl_easy_cleanup(curl); } return true; } int OpenDoor() { wiringPiSetup(); pinMode(29,OUTPUT); //初始化引脚为输出口 digitalWrite(29,HIGH); if(flag==0){ digitalWrite(29,LOW); //把引脚置为高电平 sleep(1); digitalWrite(29,HIGH); } else if(flag ==1 ){ } printf("%d\n",flag); return 0; } int main(void) { system("raspistill -o file1.jpg"); postUrl("/tmp/post.html"); OpenDoor(); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。