人流统计动态版 in out数据为零的解决方法
kunga0814 发布于2019-09 浏览:2889 回复:3
1
收藏

谷雨信息科技gooyuit

第一次请求:caseId=0  case_init=true

第二次请求:caseId>0  case_init=false

百度文档说明:caseId是,任务ID(通过case_id区分不同视频流,自拟,不同序列间不可重复即可)

第二次请求开始,caseId必须是相同,代表的是同一个视频流。

package com.hz.action.wx.face;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;

import org.apache.struts2.ServletActionContext;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame;
import org.json.JSONArray;
import org.json.JSONObject;

import com.hz.action.wx.WxCommAction;
import com.hz.service.face.AuthService;
import com.hz.service.face.Base64Util;
import com.hz.service.face.HttpUtil;
import com.hz.service.face.VideoFrame2ImageUtil;
import com.hz.service.util.http.JsoupUtil;
import com.hz.vo.face.FaceBean;

import sun.misc.BASE64Decoder;


public class Face{
	private static final long serialVersionUID = -7203036953794071188L;

	private FaceBean faceBean;
	private static int case_id = 0;
	private static String BODY_TRACKING_URL="https://aip.baidubce.com/rest/2.0/image-classify/v1/body_tracking";
	public void getCount() throws Exception{
		String path = ServletActionContext.getServletContext().getRealPath("/wx/face/face_img");
		Integer fnum = getFaceBean().getFileNum();
		File file = new File(path+"/face_"+fnum+".jpg");
		BufferedImage bi = ImageIO.read(file);
		setCont(bi);
	}
	
	public static void main(String[] args) {
		//预先保存图片
		String videoPath = "E:\\workspace\\account\\web\\wx\\face\\face05.mp4";
		VideoFrame2ImageUtil.saveVideoFramerImage(videoPath, "E:\\workspace\\account\\web\\wx\\face\\face_img");
	}
	
	private void setCont(BufferedImage bufferedImage) throws Exception {
		String access_token = AuthService.getAuth();
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ImageIO.write(bufferedImage, "jpg", baos);
		//转为base64
		String case_init = null;
		if(case_id == 0) {
			case_init = "true";
			case_id++;
		}else {
			case_init = "false";
		}
		String base64 = Base64Util.encode(baos.toByteArray());
		String params = "show=true&dynamic=" + "true" + "&case_id=" + case_id + "&case_init=" + case_init + "&image=" + URLEncoder.encode(base64,"utf-8") + "&area=" + "1,250,850,250,850,479,1,479";
		String result = HttpUtil.post(BODY_TRACKING_URL, access_token, params );
		JSONObject obj = new JSONObject(result);
		int person_num = obj.getInt("person_num");
		System.out.println("num="+obj.getInt("person_num")+",in="
		+obj.getJSONObject("person_count").getInt("in")
		+",out="+
		+obj.getJSONObject("person_count").getInt("out")+"\n");
		printlnToClient(obj.toString());
		//case_id++;
		
		BASE64Decoder decoder = new BASE64Decoder();
		String savePath = "E:\\workspace\\account\\web\\wx\\face\\face_after_img";
		
		String imgStr = obj.getString("image");
		if(null != imgStr && imgStr.length() > 0) {
			//Base64解码
			byte[] b = decoder.decodeBuffer(imgStr);
			for(int i=0;i
收藏
点赞
1
个赞
共3条回复 最后由爱鸡涌1314回复于2020-04
#4爱鸡涌1314回复于2020-04

请问你的area是怎么设置的

0
#3wangwei8638回复于2019-10

可以参考,不过是python3 写的

0
#2wangwei8638回复于2019-10

https://ai.baidu.com/forum/topic/show/943751

0
TOP
切换版块