#include "ContourSelector.h" /* #include #include "Utils.h" #define LOG_TAG "NDK" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) #define ITEM_SIZE 16 */ #define MIN_VALUE 5 ContourSelector::ContourSelector() { } ContourSelector:: ~ContourSelector() { } void ContourSelector::CalContoursGf(Mat & src, ContoursTExtend & contours, VectorPT &vectorPT) { for (unsigned int i = 0; i < contours.size(); i++) { ContourGfExtend *pContourGf = new ContourGfExtend(); vector &pContour = contours.at(i); cv::Rect rect = boundingRect(pContour); cv::RotatedRect roteRect=minAreaRect(pContour); pContourGf->setContourArea((int)contourArea(pContour)); pContourGf->setContourPerimeter((int)arcLength(pContour, true)); pContourGf->setRotatedRect(roteRect); pContourGf->setContourIndex(i); int width=max(roteRect.size.height,roteRect.size.width); int height=min(roteRect.size.height,roteRect.size.width); //pContourGf->setContourArea(width*height); pContourGf->setSize(cv::Size(rect.width,rect.height)); pContourGf->setContourAspectRatio((double)height/width);//����� pContourGf->setContourRectangularity((double)pContourGf->getContourArea()/(width*height));//���ζ� pContourGf->setContourCenter((int)roteRect.center.x, (int)roteRect.center.y); pContourGf->setLeftTop(rect.x, rect.y); pContourGf->setRightBottom(rect.x + rect.width, rect.y + rect.height); cv::Rect roi((int)roteRect.center.x,(int)roteRect.center.y,MIN_VALUE,MIN_VALUE); if (roi.x+MIN_VALUE>(src.cols-1) ||roi.y+MIN_VALUE>(src.rows-1) ||widthsetColorPercentage(rp,gp,bp); pContourGf->setContourGrayValue(avgSum/3); PairTExtend v ; v.first = &pContour; v.second = pContourGf; vectorPT.push_back(v); } } void ContourSelector::SelectObj(const VectorPT& vectorPT1, VectorPT& vectorPT2, const vector&indices) { int count=vectorPT1.size(); for (int i=0;i=0&&indexsecond; double gfValue=0.0; switch (gf) { case Perimeter: { gfValue = pContourGf->getContourPerimeter(); } break; case Area: { gfValue = pContourGf->getContourArea(); } break; case CenterX: { gfValue = pContourGf->getContourCenter().x; } break; case CenterY: { gfValue = pContourGf->getContourCenter().y; } break; case LeftTopX: { gfValue = pContourGf->getLeftTop().x; } break; case LeftTopY: { gfValue = pContourGf->getLeftTop().y; } break; case RightBottomX: { gfValue = pContourGf->getRightBottom().x; } break; case RightBottomY: { gfValue = pContourGf->getRightBottom().y; } break; case AspectRatio: { gfValue=pContourGf->getContourAspectRatio(); } break; case Rectangularity: { gfValue=pContourGf->getContourRectangularity(); } break; //�Ҷ�ֵ case GrayValue: { gfValue=pContourGf->getContourGrayValue(); } break; case Width: { gfValue=pContourGf->getSize().width; } break; case Height: { gfValue=pContourGf->getSize().height; } break; case RedPercentage: { gfValue=pContourGf->getColorPercentage(0); } break; case GreenPercentage: { gfValue=pContourGf->getColorPercentage(1); } break; case BluePercentage: { gfValue=pContourGf->getColorPercentage(2); } break; } if (gfValue>=minValue&&gfValue<=maxValue) { PairTExtend pt; pt.first=it->first; pt.second=it->second; vectorPT2.push_back(pt); } } }