d6aeede2bc
从桌面工程复制而来,作为本仓库的 Xuxucheck/ 子目录。 为控制仓库体积做了两处删减: - 移除 Frameworks/opencv2.xcframework 下的两个 visionOS 切片 (xros-arm64、xros-arm64-simulator,合计约 106 MB),并同步删掉该 xcframework 内 Info.plist 里对应的两条 AvailableLibraries 记录, 只保留 ios-arm64 与 ios-arm64_x86_64-simulator。 - 移除全部 .DS_Store 与 xcuserdata/。 已用 xcodebuild 从本目录完整编译验证:BUILD SUCCEEDED, ProcessXCFramework 以 --platform ios 成功选中框架,产物含 3699 个 cv:: 符号 (OpenCV 确实链入),嵌入 framework 3 个,与移除无用 pod 之后的状态一致。 仓库约 206 MB,其中 OpenCV 203 MB、其余源码与依赖约 3 MB。
191 lines
4.4 KiB
C++
191 lines
4.4 KiB
C++
#include "ContourSelector.h"
|
|
|
|
/*
|
|
#include <android/log.h>
|
|
#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<cv::Point> &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)
|
|
||width<MIN_VALUE
|
|
||height<MIN_VALUE)
|
|
{
|
|
delete pContourGf;
|
|
continue;
|
|
}
|
|
Mat roiSrc(src,roi);
|
|
cv::Scalar avg=mean(roiSrc);
|
|
double avgSum=avg.val[0]+avg.val[1]+avg.val[2];
|
|
double bp=avg.val[0]/avgSum;
|
|
double gp=avg.val[1]/avgSum;
|
|
double rp=avg.val[2]/avgSum;
|
|
pContourGf->setColorPercentage(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<int>&indices)
|
|
{
|
|
int count=vectorPT1.size();
|
|
for (int i=0;i<indices.size();++i)
|
|
{
|
|
int index=indices[i];
|
|
if (index>=0&&index<count)
|
|
{
|
|
vectorPT2.push_back(vectorPT1[index]);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ContourSelector::SelectContour(VectorPT& vectorPT1,
|
|
VectorPT& vectorPT2,
|
|
double minValue,
|
|
double maxValue,
|
|
GF_FLAG gf)
|
|
{
|
|
VectorPT::iterator it=vectorPT1.begin();
|
|
for (;it!=vectorPT1.end();++it)
|
|
{
|
|
ContourGfExtend *pContourGf=it->second;
|
|
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);
|
|
}
|
|
}
|
|
}
|