完成读取bin文件数据然后根据数据用opencv人脸框功能:
ReadBinAndDraw.cpp:
// ReadBinAndDraw.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 共112张图片,按每个图片只取一个人脸框来算,一个人脸框有x,y,width,height 四个int数据,
#include <stdio.h>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#define BIN_FILE "Retina640x480_result.bin"
#define NUM (112)
#define DIRNAME_JPEG ".\\640x480\\"
#define DIR_OUT "./640x480_out/"
using std::cout;
using std::endl;
class Rect2i {
public:
Rect2i() : x(0), y(0), width(0), height(0) { };
Rect2i(int _x, int _y, int _width, int _height) : x(_x), y(_y), width(_width), height(_height) { };
~Rect2i() {};
public:
int x; //!< x coordinate of the top-left corner
int y; //!< y coordinate of the top-left corner
int width; //!< width of the rectangle
int height; //!< height of the rectangle
};
class Anchor {
public:
Rect2i finalbox; // final box res
};
int buff[NUM * 4];
char inJpgFileName[30];
char outFileName[30];
Anchor result[NUM];
int buff2[NUM * 4] =
{
155,146,251,239, 325,127,453,299, 282,114,344,186, 355,134,484,297, 397,236,437,281, //1-5
250,87,396,273, 280,120,413,304, 357,159,432,252, 254,150,321,230, 311,149,409,282, //6-10
245,117,301,187, 317,126,461,305, 311,182,375,265, 239,41,361,210, 300,124,403,260, //11-15
257,114,355,244, 300,61,407,204, 246,73,412,298, 323,98,408,214, 302,97,414,258, //16-20
182,91,315,272, 242,64,408,273, 343,87,486,277, 323,82,454,241, 251,54,380,213, //21-25
249,123,356,264, 305,120,362,186, 350,90,483,260, 231,124,366,303, 221,113,391,343, //26-30
172,108,352,359, 351,147,443,266, 387,129,475,241, 395,86,467,177, 161,58,363,245, //31-35
279,73,414,244, 344,91,434,199, 266,113,390,275, 192,95,338,276, 353,117,463,253, //36-40
381,92,475,209, 299,91,387,213, 313,64,378,143, 214,138,352,309, 269,122,396,303, //41-45
221,129,306,240, 324,92,467,269, 255,69,468,362, 263,125,409,304, 298,174,387,291, //46-50
359,165,430,254, 251,76,444,337, 330,212,384,277, 290,113,393,234, 342,118,411,206, //51-55
247,86,332,206, 287,68,460,287, 228,175,378,365, 399,135,551,309, 340,97,448,234, //56-60
152,143,322,360, 408,66,493,183, 327,97,396,183, 260,38,470,322, 281,122,404,283, //61-65
193,104,392,322, 114,101,253,275, 351,103,436,211, 348,112,454,259, 334,98,458,254, //66-70
399,71,564,244, 164,35,412,359, 239,133,335,265, 332,57,445,202, 383,117,432,177, //71-75
185,71,447,427, 301,105,389,218, 378,64,467,177, 201,112,301,251, 305,298,362,370, //76-80
326,94,411,199, 468,79,553,189, 296,97,404,235, 319,137,447,296, 223,67,396,292, //81-85
265,137,333,220, 293,77,422,244, 203,87,269,166, 319,56,516,332, 219,66,284,145, //86-90
225,131,281,202, 222,63,414,328, 246,83,464,355, 163,24,383,314, 258,81,392,245, //91-95
154,90,297,279, 300,124,403,260, 186,74,285,200, 185,83,330,259, 245,86,382,263, //96-100
323,22,440,175, 245,94,445,359, 228,132,290,211, 276,173,384,303, 330,113,414,222, //101-105
383,117,432,177, 306,108,419,248, 301,89,412,232, 252,96,418,312, 334,131,447,279, //106-110
205,100,431,400,
};
int main()
{
// FILE* fp1 = fopen(BIN_FILE,"rb");
// if(nullptr == fp1){
// printf("\n error: open bin file failed \n");
// while (1);
// return -1;
// }
// size_t num = fread(buff, sizeof(int), NUM*4, fp1);
// num = num / 4;
// if(num > NUM){
// printf("\n error: fread num is wrong \n");
// while (1);
// return -1;
// }
// else{
// printf("\n fread num is %d \n",num);
// }
//
// fclose(fp1);
for (int i = 0, j=0; i < NUM*4; i+=4,j++) {
//result[j].finalbox.x = buff[i];
//result[j].finalbox.y = buff[i + 1];
//result[j].finalbox.width = buff[i + 2];
//result[j].finalbox.height = buff[i + 3];
result[j].finalbox.x = buff2[i];
result[j].finalbox.y = buff2[i + 1];
result[j].finalbox.width = buff2[i + 2];
result[j].finalbox.height = buff2[i + 3];
}
for (int kk = 0; kk < NUM; kk++) {
sprintf(inJpgFileName, DIRNAME_JPEG"%03d.jpeg", kk+1);
sprintf(outFileName, DIR_OUT"%03d_out.jpeg", kk+1);
cv::Mat img = cv::imread(inJpgFileName);
std::cout << "result " << kk << std::endl;
cout << (int)result[kk].finalbox.x << endl;
cout << (int)result[kk].finalbox.y << endl;
cout << (int)result[kk].finalbox.width << endl;
cout << (int)result[kk].finalbox.height << endl;
cv::rectangle(img, cv::Point((int)result[kk].finalbox.x, (int)result[kk].finalbox.y), cv::Point((int)result[kk].finalbox.width, (int)result[kk].finalbox.height), cv::Scalar(0, 255, 255), 2, 8, 0);
//#define CIRCLE_RADIUS 5
// cv::Point pts(result[i].pts[0].x, result[i].pts[0].y);
// cv::circle(img, pts, CIRCLE_RADIUS, cv::Scalar(0, 255, 0), -1);
// pts.x = result[i].pts[1].x;
// pts.y = result[i].pts[1].y;
// cv::circle(img, pts, CIRCLE_RADIUS, cv::Scalar(0, 255, 0), -1);
// pts.x = result[i].pts[2].x;
// pts.y = result[i].pts[2].y;
// cv::circle(img, pts, CIRCLE_RADIUS, cv::Scalar(0, 255, 0), -1);
// pts.x = result[i].pts[3].x;
// pts.y = result[i].pts[3].y;
// cv::circle(img, pts, CIRCLE_RADIUS, cv::Scalar(0, 255, 0), -1);
// pts.x = result[i].pts[4].x;
// pts.y = result[i].pts[4].y;
// cv::circle(img, pts, CIRCLE_RADIUS, cv::Scalar(0, 255, 0), -1);
cv::imwrite(outFileName, img);
}
return 0;
}