int Load_Image(const char *filepath, LCUI_Graph *out) /* * 功能:载入指定图片文件的图形数据 * 说明:打开图片文件,并解码至内存,打开的图片文件越大,占用的内存也就越大 * */ { FILE *fp; int result = 0; /* 错误代号为0 */ Graph_Init(out); out->have_alpha = IS_FALSE; /*fp是全局变量,其它函数会用到它*/ if ((fp = fopen(filepath,"r")) == NULL) { perror(filepath); result = OPEN_ERROR; } else { fgetc(fp); if (!ferror (fp)) {/*r如果没出错*/ fseek(fp,0,SEEK_END); if (ftell(fp)>4) { fclose(fp); result = detect_image(filepath, out); } else { result = SHORT_FILE;//文件过小 fclose(fp); } } } return result; /* 返回错误代码 */ }
DARNIT_TILESHEET *next_image(DARNIT_IMAGE_DATA img, int *piczels) { int i, j; for (i = 0; i < img.w; i++) for (j = 0; j < img.h; j++) if (img.data[i + j * img.w] == PIXEL_SOLID) return detect_image(img, i, j, piczels); return NULL; }
//==============================================================// void ObjDetector::detect(cv::Mat src, std::vector<cv::Rect>& box, std::vector<float>& vote) { int i, j; float m=m_slidParam.m_init_scale; box.clear(); vote.clear(); std::cout << "original size: " << src.size() << std::endl; std::cout << "objsize: " << m_objsize[0] << "/" << m_objsize[1] << "\n"; for(i=0; i<m_slidParam.m_scale_num; ++i, m*=m_slidParam.m_shrink_ratio) { cv::Size newSize(src.cols*m, src.rows*m); //std::cout << "objsize: " << m_objsize[0] << "/" << m_objsize[1] << "\n"; std::cout << i << ": scale " << m << "\n"; int maxlen = 2048; if(newSize.width>maxlen || newSize.height>maxlen) { std::cout << "**** image size > " << maxlen << "\n"; std::cout << "**** stop detection\n"; continue; } if(newSize.width<m_objsize[0] || newSize.height<m_objsize[1]) { break; } cv::Mat resized; cv::resize(src, resized, newSize, 0, 0, cv::INTER_AREA); std::vector<cv::Rect> tempbox; std::vector<float> tempvote; detect_image(resized, m, tempbox, tempvote); box.insert(box.end(), tempbox.begin(), tempbox.end()); vote.insert(vote.end(), tempvote.begin(), tempvote.end()); } //remove overlapping area if(m_remove_overlap) { for(i=0; i<vote.size(); ++i) { bool toremove=false; for(j=0; j<vote.size(); ++j) { if(i!=j) { if( vote[i]<=vote[j] && overlapRatio(box[i],box[j])>m_overlap_thres) { toremove=true; break; } //if( (box[i]&box[j])==box[i] ) // && overlapRatio(box[i],box[j])>m_overlap_thres-0.1) if( (box[i]&box[j]).area()/float(box[i].area())>0.85) { float cx = box[j].x+box[j].width/2.0; float cy = box[j].y+box[j].height/2.0; if( (box[i].x<cx && box[i].x+box[i].width >cx) ||(box[i].y<cy && box[i].y+box[i].height>cy) ) { if(vote[i]<=vote[j]) { toremove=true; break; } else { vote.erase(vote.begin()+j); box.erase(box.begin()+j); --j; } } } } } if(toremove) { vote.erase(vote.begin()+i); box.erase(box.begin()+i); --i; } } } }