Commit ed5d7544 张士柳

1 个父辈 1d76f9a7
此文件太大,无法显示。
......@@ -20,7 +20,7 @@ namespace eyemLib_Sharp
string[] fileNames = Directory.GetFiles(@"D:\批量测试图像\", "*.*", SearchOption.AllDirectories);
foreach (var item in fileNames)
{
if (item.EndsWith("png") || item.EndsWith("jpg") || item.EndsWith("bmp"))
if (item.EndsWith("png") || item.EndsWith("jpg") || item.EndsWith("bmp")||item.EndsWith("Png")||item.EndsWith("tif"))
{
EyemLib.eyemReadImageTool(item);
}
......
......@@ -81,9 +81,14 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\x64\Debug_V455\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
......
......@@ -984,6 +984,70 @@ static double getThreshVal_Otsu_8u(const cv::Mat& _src)
return max_val;
}
static void mFloodFill(cv::Mat& image, cv::Point location, uchar fillValue)
{
const int X = image.cols, Y = image.rows;
std::queue<cv::Point> fillPoints;
if (location.x < 0 || location.x >= X || location.y < 0 || location.y >= Y) return;
fillPoints.push(location);
#define fillAt(x,y) (image.ptr<uchar>(y)[x])
int pColor = fillAt(location.x, location.y);
while (!fillPoints.empty())
{
cv::Point p = fillPoints.front();
fillPoints.pop();
int x = p.x, y = p.y;
fillAt(x, y) = fillValue;
if (x > 0 && fillAt(x - 1, y) == pColor) {
fillAt(x - 1, y) = fillValue;
fillPoints.push(cv::Point(x - 1, y));
}
if (x < X - 1 && fillAt(x + 1, y) == pColor) {
fillAt(x + 1, y) = fillValue;
fillPoints.push(cv::Point(x + 1, y));
}
if (y > 0 && fillAt(x, y - 1) == pColor) {
fillAt(x, y - 1) = fillValue;
fillPoints.push(cv::Point(x, y - 1));
}
if (y < Y - 1 && fillAt(x, y + 1) == pColor) {
fillAt(x, y + 1) = fillValue;
fillPoints.push(cv::Point(x, y + 1));
}
}
fillPoints.swap(std::queue<cv::Point>());
}
static void fillUp(cv::Mat& image)
{
const int X = image.cols, Y = image.rows;
for (int y = 0; y < Y; y++)
{
uchar* ptr = image.ptr<uchar>(y);
if (ptr[0] == 0) mFloodFill(image, cv::Point(0, y), 127);
if (ptr[X - 1] == 0) mFloodFill(image, cv::Point(X - 1, y), 127);
}
for (int x = 0; x < X; x++)
{
uchar* ptr = image.data + x;
if (ptr[0] == 0) mFloodFill(image, cv::Point(x, 0), 127);
if (ptr[(Y - 1) * X] == 0) mFloodFill(image, cv::Point(x, Y - 1), 127);
}
for (int y = 0; y < Y; y++)
{
uchar* ptr = image.ptr<uchar>(y);
for (int x = 0; x < X; x++)
{
ptr[x] = ptr[x] == 127 ? 0 : 255;
}
}
}
int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double dMaxVal, EyemImage* tpDstImg)
{
cv::Mat image = cv::Mat(tpSrcImg.iHeight, tpSrcImg.iWidth, MAKETYPE(tpSrcImg.iDepth, tpSrcImg.iChannels), tpSrcImg.vpImage).clone();
......@@ -1012,6 +1076,12 @@ int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double
return FUNC_OK;
}
int eyemBinThresholdSubpixel()
{
return FUNC_OK;
}
int eyemBinNiBlack(EyemImage tpSrcImg, int iType, int iWinSize, double dK, int binMethod, double dR, EyemImage* tpDstImg)
{
cv::Mat src = cv::Mat(tpSrcImg.iHeight, tpSrcImg.iWidth, MAKETYPE(tpSrcImg.iDepth, tpSrcImg.iChannels), tpSrcImg.vpImage).clone();
......@@ -1514,7 +1584,6 @@ int eyemBinBlob(EyemImage tpImage, IntPtr* hObject, EyemBlobParams tpParams, Eye
return FUNC_OK;
}
bool eyemBinFree(IntPtr hObject)
{
std::vector<EyemBinBlob>* tpResult = reinterpret_cast<std::vector<EyemBinBlob>*>(hObject);
......
......@@ -87,6 +87,19 @@ int eyemImageRead(const char* fileName, int iFlag, EyemImage* tpImage)
return FUNC_OK;
}
int eyemImageWrite(const char* fileName, EyemImage tpImage)
{
cv::Mat src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (src.empty()) {
return FUNC_IMAGE_NOT_EXIST;
}
std::vector<int>params;
params.push_back(cv::IMWRITE_JPEG_QUALITY);
params.push_back(80);
bool bRet = imwrite(fileName, src, params);
return FUNC_OK;
}
int eyemImageReadRaw(const char* filename, int iWidth, int iHeight, int iDepth, EyemImage* tpImage)
{
if (std::strlen(filename) == 0)
......@@ -290,7 +303,7 @@ void eyemDrawHistogramImage(EyemImage tpImage, EyemImage* tpDstImg, int color[3]
if (incn > 1) {
cv::cvtColor(image, src, cv::COLOR_BGR2GRAY);
}
else{
else {
image.copyTo(src);
}
}
......
......@@ -41,8 +41,10 @@
#define FUNC_NOT_ENOUGH_MEM (-1) // 工作内存不足
#define FUNC_ILLEGAL_ARGUMENT (-2) // 参数不合适
#define FUNC_IMAGE_NOT_EXIST (-3) // 图像不存在
#define FUNC_RES_RELEASED (-7) // 资源被释放
#define FUNC_CANNOT_CALC (-100) // 不可计算
#define FUNC_CANNOT_USE (-999) // 不可用
#define FUNC_FILE_NOT_EXIST (-8) // 文件不存在
// 错误代码 (识别解码)
#define FUNC_FAILED_DETECT (-4) // 未识别到
......@@ -876,6 +878,7 @@ extern "C" {
EXPORTS void* eyemMallocMemBlock(int cb);
EXPORTS void eyemFreeMemBlock(void* block);
EXPORTS int eyemImageRead(const char* filename, int iFalgs, EyemImage* ucpImage);
EXPORTS int eyemImageWrite(const char* fileName, EyemImage tpImage);
EXPORTS int eyemImageReadRaw(const char* filename, int iWidth, int iHeight, int iDepth, EyemImage* tpImage);
EXPORTS int eyemImageFromBitmap(void* vpScan0, int iWidth, int iHeight, int iDepth, int iChannels, EyemImage* tpImage);
EXPORTS int eyemVideoCapture(const char* fileName, IntPtr* hObject, EyemImage** tpImages, int* ipNum);
......@@ -914,7 +917,7 @@ extern "C" {
EXPORTS int eyemInitNNDetector(const char* detectorConfigPath, const char* detectorModelPath, int iNetSizew, int iNetSizeh);
EXPORTS int eyemNNDetectorParams(float fConfidence, float fNMSThreshold);
EXPORTS int eyemNNDetector(EyemImage tpImage, int* ipNum, BboxContainer& container, EyemImage* tpDstImg);
EXPORTS int eyemNNInstanceSegment(EyemImage tpImage,float fThreshold, RotateBox& container, EyemImage* tpDstImg);
EXPORTS int eyemNNInstanceSegment(EyemImage tpImage, float fThreshold, RotateBox& container, EyemImage* tpDstImg);
//EXPORTS int eyemInitClassifier(const char* classifierConfigPath, const char* classifierModelPath, int ntype);
//EXPORTS int eyemClassifier(EyemImage tpImage);
EXPORTS int eyemInitONNXModel(const char* extractorModelPath);
......@@ -988,7 +991,7 @@ extern "C" {
EXPORTS int eyemAchvMaskImage(EyemImage tpImage, EyemImage* tpDstImg, EyemImage* tpPrevImg);
EXPORTS int eyemSplitMask(EyemImage tpImage, EyemImage tpMask, const char* ccToPath, const char* ccClassName);
EXPORTS int eyemCalcReelTHK(EyemImage tpImage, EyemImage tpMask, EyemOcsIXY*, double& dThickness);
EXPORTS int eyemCkReelStatus(EyemImage tpImage, const char* lpszConfigPath, int& iStatus);
EXPORTS int eyemCkReelStatus(EyemImage tpImage, const char* lpszConfigPath, char** lpszContent);
EXPORTS int eyemAchvRotateImage(EyemImage tpImage, EyemOcsIXY p1, EyemOcsIXY p2, EyemOcsIXY p3, EyemOcsIXY p4, EyemImage* tpDstImg);
......
......@@ -505,6 +505,8 @@
<ClInclude Include="eyemSmooth.h" />
<ClInclude Include="eyemCodeDetector.h" />
<ClInclude Include="eyemStopwatch.h" />
<ClInclude Include="json\json-forwards.h" />
<ClInclude Include="json\json.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="yoloWrapper.h" />
</ItemGroup>
......@@ -533,6 +535,7 @@
<ClCompile Include="eyemSmooth.cpp" />
<ClCompile Include="eyemCodeDetector.cpp" />
<ClCompile Include="eyemStopwatch.cpp" />
<ClCompile Include="jsoncpp.cpp" />
<ClCompile Include="libopencv.cpp" />
<ClCompile Include="yoloWrapper.cpp" />
</ItemGroup>
......
......@@ -84,6 +84,12 @@
<ClInclude Include="eyemNCCBasedMatch.h">
<Filter>源文件</Filter>
</ClInclude>
<ClInclude Include="json\json.h">
<Filter>源文件</Filter>
</ClInclude>
<ClInclude Include="json\json-forwards.h">
<Filter>源文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="eyemLib.cpp">
......@@ -164,6 +170,9 @@
<ClCompile Include="eyemNCCBasedMatch.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="jsoncpp.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="eyemLib.rc">
......
此文件的差异太大,无法显示。
......@@ -11,6 +11,10 @@
#include "eyemLib.h"
#include "azONNXWrapper.h"
// rapidjson
#include "json/json.h"
#include "json/json-forwards.h"
constexpr double c = PI / 180.;
extern Logger logger;
......
......@@ -163,11 +163,15 @@ int eyemNNInstanceSegment(EyemImage tpImage, float fThreshold, RotateBox& contai
if (src.channels() > 3) {
cv::cvtColor(src, src, cv::COLOR_BGRA2BGR);
}
cv::Mat mask(src.rows, src.cols, CV_8UC1, cv::Scalar(255));
//如果不满足尺寸给补齐
if (src.cols != 5472 || src.rows != 3648) {
cv::Mat temp;
cv::Mat temp, mask0;
cv::copyMakeBorder(src, temp, 0, 5472 - src.cols, 0, 5472 - src.rows, cv::BORDER_REPLICATE);
cv::copyMakeBorder(mask, mask0, 0, 5472 - src.cols, 0, 5472 - src.rows, cv::BORDER_CONSTANT, cv::Scalar(0));
src = temp(cv::Rect(0, 0, 5472, 3648)).clone();
mask = mask0(cv::Rect(0, 0, 5472, 3648)).clone();
}
//画图
cv::Mat showResult;
......@@ -194,6 +198,8 @@ int eyemNNInstanceSegment(EyemImage tpImage, float fThreshold, RotateBox& contai
//
cv::Mat label;
cv::threshold(dst, label, 190, 255, cv::THRESH_BINARY);
//去掉多余部分
cv::bitwise_and(label, mask, label);
//判断矩形
std::vector<std::vector<cv::Point>> contours;
findContours(label, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
......@@ -202,11 +208,11 @@ int eyemNNInstanceSegment(EyemImage tpImage, float fThreshold, RotateBox& contai
for (int i = 0; i < contours.size(); i++)
{
if (cv::contourArea(contours[i]) > cvRound(180000 * fThreshold)) {
cv::approxPolyDP(cv::Mat(contours[i]), poly[i], cv::arcLength(contours[i], true) * 0.03, true);
cv::approxPolyDP(cv::Mat(contours[i]), poly[i], cv::arcLength(contours[i], true) * 0.07, true);
//最小外包矩形
cv::RotatedRect rRect;
cv::Point2f pts[4];
rRect = cv::minAreaRect(poly[i]);
rRect = cv::minAreaRect(contours[i]);//从poly修改,标签分割可修改回去
rRect.points(pts);
//
cv::Rect bbox = cv::boundingRect(contours[i]);
......
此文件的差异被折叠, 点击展开。
此文件的差异太大,无法显示。
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!