当前位置: 代码迷 >> Android >> 请用android语言改写下面c++代码,TKS!解决方法
  详细解决方案

请用android语言改写下面c++代码,TKS!解决方法

热度:6   发布时间:2016-05-01 21:03:18.0
请用android语言改写下面c++代码,TKS!
#include <stdio.h>
#include "FaceDetectDef.h"
#include "FaceDetectMain.h"
#include <time.h>
#include "stdlib.h"

#include "BvsDriverState.h"

#define MAXFACESINPHOTO 50

/* ==== RGB ==== */
#define CHID_R 0
#define CHID_G 1
#define CHID_B 2

#define val_pixel_image( img, x, y, ch, x_num, y_num, ch_num ) \
( img[( (y) * (x_num) + (x) ) * (ch_num) + ch] )

/* rgb from rgb */
#define val_r_rgb( img, x, y, x_num, y_num ) ( val_pixel_image( img, x, y, CHID_R, x_num, y_num, 3 ) )
#define val_g_rgb( img, x, y, x_num, y_num ) ( val_pixel_image( img, x, y, CHID_G, x_num, y_num, 3 ) )
#define val_b_rgb( img, x, y, x_num, y_num ) ( val_pixel_image( img, x, y, CHID_B, x_num, y_num, 3 ) )

/* ycbcr from rgb */
#define val_y_rgb( img, x, y, x_num, y_num ) \
( ( 77 * val_r_rgb( img, x, y, x_num, y_num ) \
+ 151 * val_g_rgb( img, x, y, x_num, y_num ) \
+ 28 * val_b_rgb( img, x, y, x_num, y_num ) ) >> 8 )

/* ---- Clip ---- */
#define limit( x, a, b ) ( ( ( x ) < ( a ) ) ? ( a ) : ( ( ( x ) > ( b ) ) ? ( b ) : ( x ) ) )
#define clip( x ) limit( x, 0, 255 )

#define BYTES_OF_PERLINE(width, bitcount) ((((width * bitcount) + 31) & ~31) >> 3)
#define BYTE unsigned char


BYTE * readBVImage(char *szFileName, int *nWidth, int *nHeight){
BYTE *pY = NULL;
int size = 0;
FILE *fp = NULL;

fp = fopen(szFileName, "rb");
//assert(fp!=NULL);
if (fp==NULL){
*nWidth = 0;
*nHeight = 0;
return NULL;
}

//now read all;
fread(nWidth, sizeof(int), 1, fp);
fread(nHeight, sizeof(int), 1, fp);
size = (*nWidth) * (*nHeight) * 1;
pY = (BYTE *) malloc(size*sizeof(BYTE));
fread(pY, sizeof(BYTE), size, fp);


fclose(fp);
return pY;
}

//void ConvertBGR24toY( const unsigned char* in_pImage, const int in_Width, const int in_Height, unsigned char* io_pYImage )
//{
// int x, y;
// /* Parameter check */
// if( in_pImage == NULL ||
// io_pYImage == NULL ) {
//
// }
//
// for ( y = 0 ; y < in_Height ; y++ ) {
// for ( x = 0 ; x < in_Width ; x++ ) {
// io_pYImage[in_Width * y + x] = ( unsigned char ) clip( val_y_rgb( in_pImage, x, y, in_Width, in_Height ) );
// }
// }
//
//}


int main(void) {
FaceRecognitionHandle m_pFaceInstance=NULL;
BYTE * pY = NULL;
FACEINFO io_pFace[MAXFACESINPHOTO]; 
char szFileName[1024];
char szYFileName[1024];
char szMessage[1024];
int nWidth;
int nHeight;
int nFaces=MAXFACESINPHOTO;
FILE * fp = NULL;
long t = 0;
int ret = 0;
int nF = 0;

CBvsDriverState stateFrame; //处理一帧的状态

printf("start now.\n");

fp = fopen("c:\\DetectResult.txt", "a");
//
//Initialize(&m_pFaceInstance);

stateFrame.BvsInitialize();
stateFrame.BvsSetSensitiveLevel(1);

for (int i=20; i<958; i++){
sprintf(szFileName, "..\\test_images\\Frame%05d.y", i);
pY = readBVImage(szFileName, &nWidth, &nHeight);



if (pY == NULL){
sprintf(szMessage, "read image file error %s \n", szFileName);
fputs(szMessage, fp);
continue;
}

//将图像数据转换成灰度图像数据
//BYTE * pY = new BYTE[nWidth * nHeight];
//ConvertBGR24toY(pRaw8, nWidth, nHeight, pY);

//sprintf(szYFileName, "..\\test_images\\Frame%05d.y", i);
//
//FILE * fp1 = fopen(szYFileName, "wb");
//if (fp1)
//{
// fwrite(&nWidth, sizeof(int), 1, fp1);
// fwrite(&nHeight, sizeof(int), 1, fp1);
  相关解决方案