1.1、安装mjpg-streamer
在CRT中依次输入一下指令
sudo apt-get update #更新软件列表
sudo apt-get upgrade #更新软件
sudo apt-get install subversion #Subversion是一个自由开源的版本控制系统
sudo apt-get install libjpeg8-dev #JPEG支持库
sudo apt-get install imagemagick
sudo apt-get install libv4l-dev #4l是小写"L"
sudo apt-get install cmake #下载编译工具
sudo apt-get install git
git clone https://github.com/jacksonliam/mjpg-streamer.git
cd mjpg-streamer/mjpg-streamer-experimental //进入该目录
make all //编译
sudo make install//安装
编译与安装完之后,修改start.sh 文件
vi start.sh
将原本的
./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"
修改为
./mjpg_streamer -i "./input_raspicam.so" -o "./output_http.so -w ./www"
然后打开摄像头功能
sudo rasp-config
选择第5项,按下回车键
选择P1按下回车键
打开摄像头功能之后,运行start.sh可执行文件
./start.sh
通过网页访问http://IP地址:8080,可查看摄像头拍摄内容
#include
#include
#include
#include
#include
#include
#include
#include
#define true 1
#define false 2
typedef unsigned int bool;
char buf[1024] = {
'\0'};
char *pictureTrangeBase64(char *fileName)
{
char cmd[128] = {
'\0'};
char *img;
int f_size;
int fd;
sprintf(cmd,"base64 %s > tmpzhp",fileName);
system(cmd);
fd = open("./tmpzhp",O_RDWR);
f_size = lseek(fd,0,SEEK_END);
lseek(fd,0,SEEK_SET);
img = (char *)malloc(f_size+2);
memset(img,0,f_size+2);
read(fd,img,f_size);
close(fd);
return img;
}
size_t readData( void *ptr, size_t size, size_t nmemb, void *stream)
{
strncpy(buf,ptr,1024);
}
bool postUrl()
{
CURL *curl;
CURLcode res;
char *img1;
char *img2;
char *key = "Youself Key";//在翔云平台购买人脸识别,会给你提供
char *secret = "Youself secret";
int typeId = 21;
char *format = "xml";
char *postString;
int len;
int num;
printf("Do you want to go home? if yes please input 1:\n");
scanf("%d",&num);
if(num == 1){
printf("Please display you face.\n");
system("raspistill -o zhp2.jpg -q 5");
}
img1 = pictureTrangeBase64("./zhp1.jpg"); //将图片转为64流
img2 = pictureTrangeBase64("./zhp2.jpg");
len = strlen(key)+strlen(secret)+strlen(img1)+strlen(img2)+128;
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);
free(img1);
free(img2);
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_URL, "https://netocr.com/api/faceliu.do"); // 指定url
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION ,readData);
res = curl_easy_perform(curl);
printf("OK ,%d\n",res);
if(strstr(buf ,"是") != NULL){
printf("the same people.\n");
}else{
printf("differ people.\n");
}
}
free(postString);
return true;
}
int main(void)
{
postUrl();
}
总结:一开始我对这条命令并不是很理解raspistill -o zhp2.jpg -q 5
就通过命令
raspistill --help//查询这个命令的具体用法
“raspisstill”是摄像头应用程序,在特定时间内运行相机,并在需要时进行JPG捕捉
图像参数的命令:
-q:设置图片的大小,取值范围为(0,100);从翔云平台可以得知,识别图片不能够过大。
-0:输出文件名<文件名>(要写入标准输出,使用’-o -’)。如果未指定,则不保存任何文件
-t:拍照前及关机时间(如未指定,设为5s)