C++连接百度云人脸识别功能失败,求大神帮助

natemao90 2018-12-27 09:43:29
根据百度云人脸识别的使用说明,我编写了如下的程序,可是在服务器的返回值中一直没有信息显示,请各位大神帮忙看看。
百度云后台显示,无法解析人脸,我直接连接电脑的摄像头进行实时识别,可是无法实现,求各位大神帮忙


以下是我识别部分的代码

CFaceDetect Class

#pragma once

#include "stdafx.h"
#include "CFaceDetect.h"
#include "extern.h"
#include "Base64Code.h"
#include "Lib/aip-cpp-sdk-0.7.4/face.h"
const BYTE Base64ValTab[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
#define AVal(x) Base64ValTab[x]

CFaceDetect::CFaceDetect()
{

}


CFaceDetect::~CFaceDetect()
{

}
DWORD ThreadFaceDetect(LPVOID param)
{
return ((CFaceDetect *)param)->FaceDetectLoop();
}


BOOL CFaceDetect::OnInitDialog()
{
CDialogEx::OnInitDialog();

// TODO: 在此添加额外的初始化



return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}



// //mlm 2018.12.06 人脸识别循环
DWORD CFaceDetect::FaceDetectLoop()
{
// TODO: 在此处添加实现代码.

aip::Face *m_pClient;
std::string app_id = "15018571";
std::string api_key = "nlTXGdnd7kT27pynHnYG4g6A";
std::string secret_key = "59M4GmTl0dG1nGmm7qtRvhWFxf7BiA3H";
std::string access_URL = "https://aip.baidubce.com/rest/2.0/face/v3/detect";
m_pClient = new aip::Face(app_id, api_key, secret_key);
CBase64Code CodeTranformer;
Json::Value JResult;
std::string Image_Type = "BASE64";
std::map<std::string, std::string> Options;
//Options["face_field"] = "age";
//Options["max_face_num"] = "2";
//Options["face_type"] = "LIVE";
while (!g_bDisplayThreadStop)
{
char *base64code;
std::string sResult;
//sResult = CodeTranformer.EncodeUchartoBase64(g_Oneshot, g_nDisplayWidth * g_nDisplayHeight / 4);
sResult = CodeTranformer.Encode2(g_Oneshot, g_nDisplayWidth * g_nDisplayHeight);
JResult = m_pClient->detect(sResult,Image_Type,Options);

int nnnnnn = 0;
}
return 0;
}



acquireContinuous.cpp

#include "stdafx.h"
#include "AcquireContinuous.h"
#include "extern.h"

#include <opencv2/opencv.hpp>
using namespace cv;
extern VideoCapture g_Cap;
DWORD WINAPI acquireContinuous(LPVOID lpParam)
{
while (!g_bDisplayThreadStop)
{
//mlm 2018.12.05 move from DisplayWnd.h --> int CDisplayWnd::Render(void);
Mat frame;
g_Cap >> frame;
for (int j = 0; j < frame.rows; j++)
{
BYTE* data = frame.ptr<BYTE>(j);
for (int i = 0; i < frame.cols; i++)
{
//g_Snapshot[(j * frame.cols + i) * 4 + 0] = *(frame.ptr<unsigned char>(j * frame.cols + i + 0));
//g_Snapshot[(j * frame.cols + i) * 4 + 1] = *(frame.ptr<unsigned char>(j * frame.cols + i + 1));
//g_Snapshot[(j * frame.cols + i) * 4 + 2] = *(frame.ptr<unsigned char>(j * frame.cols + i + 2));

//mlm 2018.12.05 正图像
//g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + 0] = data[i * 3 + 0];
//g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + 1] = data[i * 3 + 1];
//g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + 2] = data[i * 3 + 2];
//g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + 4 + 0] = data[i * 3 + 0];
//g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + 4 + 1] = data[i * 3 + 1];
//g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + 4 + 2] = data[i * 3 + 2];
//g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + frame.cols * 8 + 0] = data[i * 3 + 0];
//g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + frame.cols * 8 + 1] = data[i * 3 + 1];
//g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + frame.cols * 8 + 2] = data[i * 3 + 2];
//g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + frame.cols * 8 + 4 + 0] = data[i * 3 + 0];
//g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + frame.cols * 8 + 4 + 1] = data[i * 3 + 1];
//g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + frame.cols * 8 + 4 + 2] = data[i * 3 + 2];
//==>如下
memcpy(&g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + 0], &data[i * 3 + 0], sizeof(BYTE) * 3);
memcpy(&g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + 4 + 0], &data[i * 3 + 0], sizeof(BYTE) * 3);
memcpy(&g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + frame.cols * 8 + 0], &data[i * 3 + 0], sizeof(BYTE) * 3);
memcpy(&g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + frame.cols * 8 + 4 + 0], &data[i * 3 + 0], sizeof(BYTE) * 3);
memcpy(&g_Oneshot[(j * frame.cols * 4 + i * 2) + 0], &data[i * 3 + 0], sizeof(BYTE) * 3);
//mlm 2018.12.05 逆图像
//memcpy(&g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + 0], &data[(frame.cols - i - 1) * 3 + 0], sizeof(unsigned char) * 3);
//memcpy(&g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + 4 + 0], &data[(frame.cols - i - 1) * 3 + 0], sizeof(unsigned char) * 3);
//memcpy(&g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + frame.cols * 8 + 0], &data[(frame.cols - i - 1) * 3 + 0], sizeof(unsigned char) * 3);
//memcpy(&g_Snapshot[(j * frame.cols * 4 + i * 2) * 4 + frame.cols * 8 + 4 + 0], &data[(frame.cols - i - 1) * 3 + 0], sizeof(unsigned char) * 3);

}
}
SetEvent(g_hDisplayWnd);
}

return 0;
}

CBase64Code Class

#include "stdafx.h"
#include "Base64Code.h"

CBase64Code::CBase64Code()
{
}


CBase64Code::~CBase64Code()
{
}
std::string CBase64Code::Encode2(const unsigned char* Data, int DataByte)
{
//编码表
const char EncodeTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
//返回值
std::string strEncode;
unsigned char Tmp[4] = { 0 };
int LineLength = 0;
for (int i = 0; i < (int)(DataByte / 3); i++)
{
Tmp[1] = *Data++;
Tmp[2] = *Data++;
Tmp[3] = *Data++;
strEncode += EncodeTable[Tmp[1] >> 2];
strEncode += EncodeTable[((Tmp[1] << 4) | (Tmp[2] >> 4)) & 0x3F];
strEncode += EncodeTable[((Tmp[2] << 2) | (Tmp[3] >> 6)) & 0x3F];
strEncode += EncodeTable[Tmp[3] & 0x3F];
if (LineLength += 4, LineLength == 76) { strEncode += "\r\n"; LineLength = 0; }
}
//对剩余数据进行编码
int Mod = DataByte % 3;
if (Mod == 1)
{
Tmp[1] = *Data++;
strEncode += EncodeTable[(Tmp[1] & 0xFC) >> 2];
strEncode += EncodeTable[((Tmp[1] & 0x03) << 4)];
strEncode += "==";
}
else if (Mod == 2)
{
Tmp[1] = *Data++;
Tmp[2] = *Data++;
strEncode += EncodeTable[(Tmp[1] & 0xFC) >> 2];
strEncode += EncodeTable[((Tmp[1] & 0x03) << 4) | ((Tmp[2] & 0xF0) >> 4)];
strEncode += EncodeTable[((Tmp[2] & 0x0F) << 2)];
strEncode += "=";
}

return strEncode;
}

std::string CBase64Code::Decode2(const char* Data, int DataByte, int& OutByte)
{
//解码表
const char DecodeTable[] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62, // '+'
0, 0, 0,
63, // '/'
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // '0'-'9'
0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // 'A'-'Z'
0, 0, 0, 0, 0, 0,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // 'a'-'z'
};
//返回值
std::string strDecode;
int nValue;
int i = 0;
while (i < DataByte)
{
if (*Data != '\r' && *Data != '\n')
{
nValue = DecodeTable[*Data++] << 18;
nValue += DecodeTable[*Data++] << 12;
strDecode += (nValue & 0x00FF0000) >> 16;
OutByte++;
if (*Data != '=')
{
nValue += DecodeTable[*Data++] << 6;
strDecode += (nValue & 0x0000FF00) >> 8;
OutByte++;
if (*Data != '=')
{
nValue += DecodeTable[*Data++];
strDecode += nValue & 0x000000FF;
OutByte++;
}
}
i += 4;
}
else// 回车换行,跳过
{
Data++;
i++;
}
}
return strDecode;
}



...全文
351 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouqunhai 2018-12-29
  • 打赏
  • 举报
回复
还是找百度后台吧
赵4老师 2018-12-29
  • 打赏
  • 举报
回复
找百度技术支持。

5,530

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 模式及实现
社区管理员
  • 模式及实现社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧