1 image.h中加入函数声明
void save_cut_image(int px, int py, int ph, int pw, int no, image m_img, char **names, float cut_pro, int the_class);
2 image.c中加入如下函数定义
void save_cut_image(int px, int py, int ph, int pw, int no, image m_img, char **names, float cut_pro, int the_class)
{
image copy = copy_image(m_img);
if (m_img.c == 3) rgbgr_image(copy);
int x, y, k;
char buff[256];
sprintf(buff, "results//%s%.0f%%%d.jpg", names[the_class], cut_pro, no);
printf(" cut_class :%s ...........cut_class:%.0f ", names[the_class], cut_pro);
printf(names[the_class]);
printf("%f",cut_pro);
IplImage *disp = cvCreateImage(cvSize(m_img.w, m_img.h), IPL_DEPTH_8U, m_img.c);
int step = disp->widthStep;
for (y = 0; y < m_img.h; ++y) {
for (x = 0; x < m_img.w; ++x) {
for (k = 0; k < m_img.c; ++k) {
disp->imageData[y*step + x*m_img.c + k] = (unsigned char)(get_pixel(copy, x, y, k) * 255);
}
}
}
CvMat *pMat = cvCreateMatHeader(m_img.w, m_img.h, IPL_DEPTH_8U);
CvRect rect = cvRect(px, py, pw, ph);
cvGetSubRect(disp, pMat, rect);
IplImage *pSubImg = cvCreateImage(cvSize(pw, ph), IPL_DEPTH_8U, m_img.c);
cvGetImage(pMat, pSubImg);
cvSaveImage(buff, pSubImg, 0);
free_image(copy);
}
3 在image.c 的 draw_detection_v3()中插入一下代码
插在 draw_box_width(im, left, top, right, bot, width, red, green, blue);前一行
int the_class = selected_detections[i].best_class;
float cut_pro = selected_detections[i].det.prob[the_class] * 100;
printf("cut_class :%s ...........class_pro:%.0f \n", names[the_class], cut_pro);
int pre_x = left;
int pre_y = top;
int pre_h = bot - top;
int pre_w = right - left;
save_cut_image(pre_x, pre_y, pre_h, pre_w, i, im, names, cut_pro, the_class);
printf("/************ cut and save over *****************/ \n");
重编译,运行测试图片可自动裁剪图片中的目标到 目录下的results文件夹,图片命名格式为:类名+概率+计数.jpg
4 结果展示
问题:
问题:save_cut_image重定义:不同的基类型
解决:在image.h头文件中复制一下定义就好。