链接上文进行补充
https://mp.csdn.net/mp_blog/creation/editor/130438196
进入 /home/pi/mjpg-streamer/mjpg-streamer-experimental 路径下
创建脚本 shart.sh 必须全路径
/home/pi/mjpg-streamer/mjpg-streamer-experimental/mjpg_streamer -i "/home/pi/mjpg-streamer/mjpg-streamer-experimental/input_raspicam.so" -o "/home/pi/mjpg-streamer/mjpg-streamer-experimental/output_http.so -w ./www"
给与运行权限
sudo chmod +x shart.sh
把该脚本路径配置全局变量
vi ~/.bashrc
在文件最后一行加入:
export PATH="$PATH:/该改脚本路径"
更新该文件
$ source ~/.bashrc
这样在任何文件夹下都可运行!!!
在启动监控的情况下去访问静态资源照片
上文摄像头代码加以改动
system("wget http://192.168.0.145:8080/?action=snapshot -O /home/pi/smartHose/person.jpg ");//采集静态照片
#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 "contrlDevices.h"
char buf[1024] = {'\0'};
size_t readData( void *ptr, size_t size, size_t nmemb, void *stream){
memset(buf,'\0',sizeof(buf));
strncpy(buf,ptr,nmemb);
printf("====================================get data===========================\n");
printf("%s",buf);
}
//人脸识别
int cameraInit(int pinNum)
{
curl_global_init(CURL_GLOBAL_ALL);
}
char* imgBase64FromFile(char* str){
int fd;
int len;
char* img = NULL;
char cmd[124] = {'\0'};
sprintf(cmd,"base64 %s > fileImg.txt",str);
system(cmd);
fd = open("./fileImg.txt",O_RDWR);
len = lseek(fd,0,SEEK_END);
lseek(fd,0,SEEK_SET);
img = (char*)malloc(len+2);
memset(img,'\0',len);
read(fd,img,len);
close(fd);
system("rm -r fileImg.txt");
return img;
}
char* getFaceBase64FromNet()
{
char *getFaceBase64Img;
//system("raspistill -t 2000 -o /home/pi/smartHose/person.jpg -q 5");//拍照片
system("wget http://192.168.0.145:8080/?action=snapshot -O /home/pi/smartHose/person.jpg ");//采集静态照片
while(access("/home/pi/smartHose/person.jpg",F_OK) == -1);
getFaceBase64Img = imgBase64FromFile("/home/pi/smartHose/person.jpg");
system("rm -r /home/pi/smartHose/person.jpg");
return getFaceBase64Img;
}
int cameraPostUrl(struct Devices *camera)
{
CURL *curl;
CURLcode res;
char *postString = NULL;
int len;
char *img1;
char *img2;
char *key = "DAG49DMRkLgkBUBARjSeHz";
char *secret = "58eaf7f28f3342d489bce7e446fe76e0";
int typeId = 21;
char *format = "xml";
img1 = getFaceBase64FromNet();
//img1 = imgBase64FromFile("./person.jpg");
img2 = imgBase64FromFile(camera->localAmgAddress);
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,typeId,format);
curl = curl_easy_init();
if (curl)
{
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 person!\n");
camera->ret = 1;
}else{
printf("Face recognition is not the person!\n");
camera->ret = 0;
}
curl_easy_cleanup(curl);
}
free(postString);
free(img1);
free(img2);
return 0;;
}
struct Devices camera =
{
.devicesName = "camera",
.devicesInit = cameraInit,
.postUrl = cameraPostUrl,
.localAmgAddress = "./img3.jpg",
};
struct Devices *cameraToLink(struct Devices* phead)
{
if(phead == NULL){
phead = &camera;
}else{
camera.next = phead;
phead = &camera;
}
return phead;
}
安卓APP访问监控
添加WebView 控件
<WebView
android:id="@+id/webView1"
android:layout_width="360dp"
android:layout_height="220dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="170dp" />
java代码
WebView wv = (WebView) findViewById(R.id.webView1);
//设置自己的浏览器
wv.setWebViewClient(new WebViewClient());
//wv.loadUrl("http://www.hao123.com");
wv.loadUrl("http://192.168.0.145:8080/?action=stream");
//适应手机屏幕
wv.getSettings().setUseWideViewPort(true);
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
后续等写完所有代码!!!!!!!!