Commit 04c03c6d 张士柳

1 个父辈 1181d725
using System; using System;
using System.IO; using System.IO;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace eyemLib_Sharp namespace eyemLib_Sharp
...@@ -19,9 +20,12 @@ namespace eyemLib_Sharp ...@@ -19,9 +20,12 @@ namespace eyemLib_Sharp
// }); // });
// Console.Write("请按任意键继续。。。"); // Console.Write("请按任意键继续。。。");
//} //}
foreach (var fileName in fileNames) foreach (var fileName in fileNames)
{ {
EyemLib.eyemReadImageTool(fileName); EyemLib.eyemReadImageTool(fileName);
Thread.Sleep(1);
break;
} }
Console.Write("请按任意键继续。。。"); Console.Write("请按任意键继续。。。");
Console.ReadKey(); Console.ReadKey();
......
...@@ -1244,7 +1244,7 @@ int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char *ccFileNam ...@@ -1244,7 +1244,7 @@ int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char *ccFileNam
//防止越界 //防止越界
for (int n = 0; n < 2; n++) for (int n = 0; n < 2; n++)
{ {
if (pt[n].x < 0) pt[n].x = 0.f; if (pt[n].x >= iX - 1) pt[n].x = float(iX - 1); if (pt[n].y < 0) pt[n].y = 0.f; if (pt[n].y >= iY - 1) pt[n].y = float(iY - 1); if (pt[n].x < 0) pt[n].x = 0; if (pt[n].x >= iX - 1) pt[n].x = int(iX - 1); if (pt[n].y < 0) pt[n].y = 0; if (pt[n].y >= iY - 1) pt[n].y = int(iY - 1);
} }
bool bFit = false; bool bFit = false;
//扫描像素密度,比例接近1:1记录下来,并且黑白间隔数目小大于长度的一半 //扫描像素密度,比例接近1:1记录下来,并且黑白间隔数目小大于长度的一半
......
...@@ -908,8 +908,7 @@ static int Yen(int hist[]) ...@@ -908,8 +908,7 @@ static int Yen(int hist[])
return threshold; return threshold;
} }
static double static double getThreshVal_Otsu_8u(const cv::Mat& _src)
getThreshVal_Otsu_8u(const cv::Mat& _src)
{ {
cv::Size size = _src.size(); cv::Size size = _src.size();
int step = (int)_src.step; int step = (int)_src.step;
......
...@@ -8,6 +8,31 @@ ...@@ -8,6 +8,31 @@
#include "eyemLib.h" #include "eyemLib.h"
// Chain code:
// 7 0 1
// 6 2
// 5 4 3
#define CV_CHAINCODE_UP 0 ///< Up.
#define CV_CHAINCODE_UP_RIGHT 1 ///< Up and right.
#define CV_CHAINCODE_RIGHT 2 ///< Right.
#define CV_CHAINCODE_DOWN_RIGHT 3 ///< Down and right.
#define CV_CHAINCODE_DOWN 4 ///< Down.
#define CV_CHAINCODE_DOWN_LEFT 5 ///< Down and left.
#define CV_CHAINCODE_LEFT 6 ///< Left.
#define CV_CHAINCODE_UP_LEFT 7 ///< Up and left.
const char movesE[4][3][4] = { { { -1, -1, 3, CV_CHAINCODE_UP_LEFT },{ 0, -1, 0, CV_CHAINCODE_UP },{ 1, -1, 0, CV_CHAINCODE_UP_RIGHT } },
{ { 1, -1, 0, CV_CHAINCODE_UP_RIGHT },{ 1, 0, 1, CV_CHAINCODE_RIGHT },{ 1, 1, 1, CV_CHAINCODE_DOWN_RIGHT } },
{ { 1, 1, 1, CV_CHAINCODE_DOWN_RIGHT },{ 0, 1, 2, CV_CHAINCODE_DOWN },{ -1, 1, 2, CV_CHAINCODE_DOWN_LEFT } },
{ { -1, 1, 2, CV_CHAINCODE_DOWN_LEFT },{ -1, 0, 3, CV_CHAINCODE_LEFT },{ -1, -1, 3, CV_CHAINCODE_UP_LEFT } }
};
const char movesI[4][3][4] = { { { 1, -1, 3, CV_CHAINCODE_UP_RIGHT },{ 0, -1, 0, CV_CHAINCODE_UP },{ -1, -1, 0, CV_CHAINCODE_UP_LEFT } },
{ { -1, -1, 0, CV_CHAINCODE_UP_LEFT },{ -1, 0, 1, CV_CHAINCODE_LEFT },{ -1, 1, 1, CV_CHAINCODE_DOWN_LEFT } },
{ { -1, 1, 1, CV_CHAINCODE_DOWN_LEFT },{ 0, 1, 2, CV_CHAINCODE_DOWN },{ 1, 1, 2, CV_CHAINCODE_DOWN_RIGHT } },
{ { 1, 1, 2, CV_CHAINCODE_DOWN_RIGHT },{ 1, 0, 3, CV_CHAINCODE_RIGHT },{ 1, -1, 3, CV_CHAINCODE_UP_RIGHT } }
};
typedef unsigned int CvLabel; typedef unsigned int CvLabel;
const char cvChainCodeMoves[8][2] = { const char cvChainCodeMoves[8][2] = {
......
...@@ -103,7 +103,7 @@ int eyemEdge1dGenMeasureRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY ...@@ -103,7 +103,7 @@ int eyemEdge1dGenMeasureRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY
cv::Mat filter, diffMat, one; cv::Mat filter, diffMat, one;
diffMat = convert(rotImg(roi), CV_64F); diffMat = /*convert(rotImg(roi), CV_64F)*/cv::Mat();
//计算投影 //计算投影
cv::reduce(diffMat, one, 0, cv::REDUCE_AVG, CV_64F); cv::reduce(diffMat, one, 0, cv::REDUCE_AVG, CV_64F);
...@@ -282,7 +282,8 @@ int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLi ...@@ -282,7 +282,8 @@ int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLi
cv::Mat F, G; cv::Mat F, G;
F = convert(rotImg(roi), CV_64F); //TODO:增加处理接口
F = /*convert(rotImg(roi), CV_64F)*/cv::Mat();
//高斯滤波 //高斯滤波
cv::GaussianBlur(F, G, cv::Size(3, 3), dSigma, dSigma); cv::GaussianBlur(F, G, cv::Size(3, 3), dSigma, dSigma);
...@@ -332,7 +333,7 @@ int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLi ...@@ -332,7 +333,7 @@ int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLi
cv::Mat showMat3; cv::Mat showMat3;
cv::cvtColor(convert(F, CV_8U), showMat3, cv::COLOR_GRAY2BGR); cv::cvtColor(/*convert(F, CV_8U)*/cv::Mat(), showMat3, cv::COLOR_GRAY2BGR);
EyemOcsDXY tpEdge; EyemOcsDXY tpEdge;
std::vector<EyemOcsDXY> *tpEdges = new std::vector<EyemOcsDXY>(); std::vector<EyemOcsDXY> *tpEdges = new std::vector<EyemOcsDXY>();
...@@ -435,7 +436,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine ...@@ -435,7 +436,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
cv::cvtColor(image, cc, cv::COLOR_GRAY2BGR); cv::cvtColor(image, cc, cv::COLOR_GRAY2BGR);
for (int i = 0; i < 31; i++) for (int i = 0; i < 31; i++)
{ {
cc.at<cv::Vec3b>(cv::Point2f(map1.at<double>(0, i), map2.at<double>(0, i))) = cv::Vec3b(0, 255, 0); cc.at<cv::Vec3b>(cv::Point(cvRound(map1.at<double>(0, i)), cvRound(map2.at<double>(0, i)))) = cv::Vec3b(0, 255, 0);
} }
return FUNC_OK; return FUNC_OK;
......
...@@ -9,8 +9,4 @@ ...@@ -9,8 +9,4 @@
cv::Mat convert(cv::Mat &src, const int depth);
void spatialGradient(cv::Mat src, cv::Mat &dx, cv::Mat &dy);
#endif/* __EYEM_GENERIC_H */ #endif/* __EYEM_GENERIC_H */
\ No newline at end of file \ No newline at end of file
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <Windows.h> #include <Windows.h>
#include <opencv.hpp> #include <opencv.hpp>
#include <opencv2\opencv.hpp>
#ifndef EXPORTS #ifndef EXPORTS
...@@ -578,30 +579,6 @@ enum ...@@ -578,30 +579,6 @@ enum
BINARIZATION_SAUVOLA BINARIZATION_SAUVOLA
}; };
// Chain code:
// 7 0 1
// 6 2
// 5 4 3
#define CV_CHAINCODE_UP 0 ///< Up.
#define CV_CHAINCODE_UP_RIGHT 1 ///< Up and right.
#define CV_CHAINCODE_RIGHT 2 ///< Right.
#define CV_CHAINCODE_DOWN_RIGHT 3 ///< Down and right.
#define CV_CHAINCODE_DOWN 4 ///< Down.
#define CV_CHAINCODE_DOWN_LEFT 5 ///< Down and left.
#define CV_CHAINCODE_LEFT 6 ///< Left.
#define CV_CHAINCODE_UP_LEFT 7 ///< Up and left.
const char movesE[4][3][4] = { { { -1, -1, 3, CV_CHAINCODE_UP_LEFT },{ 0, -1, 0, CV_CHAINCODE_UP },{ 1, -1, 0, CV_CHAINCODE_UP_RIGHT } },
{ { 1, -1, 0, CV_CHAINCODE_UP_RIGHT },{ 1, 0, 1, CV_CHAINCODE_RIGHT },{ 1, 1, 1, CV_CHAINCODE_DOWN_RIGHT } },
{ { 1, 1, 1, CV_CHAINCODE_DOWN_RIGHT },{ 0, 1, 2, CV_CHAINCODE_DOWN },{ -1, 1, 2, CV_CHAINCODE_DOWN_LEFT } },
{ { -1, 1, 2, CV_CHAINCODE_DOWN_LEFT },{ -1, 0, 3, CV_CHAINCODE_LEFT },{ -1, -1, 3, CV_CHAINCODE_UP_LEFT } }
};
const char movesI[4][3][4] = { { { 1, -1, 3, CV_CHAINCODE_UP_RIGHT },{ 0, -1, 0, CV_CHAINCODE_UP },{ -1, -1, 0, CV_CHAINCODE_UP_LEFT } },
{ { -1, -1, 0, CV_CHAINCODE_UP_LEFT },{ -1, 0, 1, CV_CHAINCODE_LEFT },{ -1, 1, 1, CV_CHAINCODE_DOWN_LEFT } },
{ { -1, 1, 1, CV_CHAINCODE_DOWN_LEFT },{ 0, 1, 2, CV_CHAINCODE_DOWN },{ 1, 1, 2, CV_CHAINCODE_DOWN_RIGHT } },
{ { 1, 1, 2, CV_CHAINCODE_DOWN_RIGHT },{ 1, 0, 3, CV_CHAINCODE_RIGHT },{ 1, -1, 3, CV_CHAINCODE_UP_RIGHT } }
};
// Blob 分析结果 // Blob 分析结果
typedef struct { typedef struct {
...@@ -797,6 +774,32 @@ extern "C" { ...@@ -797,6 +774,32 @@ extern "C" {
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
// 图像通用处理(eyemGeneric.cpp)
//
#ifdef __cplusplus
extern "C" {
#endif
// 函数接口
EXPORTS int eyemImageRead(const char *filename, int iFalgs, EyemImage *ucpImage);
EXPORTS int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, EyemImage *tpImage);
EXPORTS int eyemImageMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType, EyemImage *tpImage);
EXPORTS int eyemCvtImageColor(EyemImage tpImage, int iCCodes, EyemImage &tpDstImg);
EXPORTS int eyemCvtImageType(EyemImage tpImage, int rType, double alpha, double beta, EyemImage &tpDstImg);
EXPORTS int eyemImageAdd(EyemImage tpImageA, EyemImage tpImageB, EyemImage &tpImage);
EXPORTS int eyemImageSub(EyemImage tpImageA, EyemImage tpImageB, EyemImage &tpImage);
EXPORTS int eyemImageAbs(EyemImage tpImageA, EyemImage tpImageB, EyemImage &tpImage);
EXPORTS void eyemImageDisplay(const char *ccWinName, EyemImage tpImage);
EXPORTS void eyemOpenWindow(const char *ccWinName);
EXPORTS void eyemCloseWindow(const char *ccWinName);
EXPORTS void eyemImageFree(void *ipImage);
#ifdef __cplusplus
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////
// 其他工具(eyemMisc.cpp) // 其他工具(eyemMisc.cpp)
// //
...@@ -817,10 +820,6 @@ extern "C" { ...@@ -817,10 +820,6 @@ extern "C" {
EXPORTS bool eyemDetectAndDecodeFree(IntPtr hObject); EXPORTS bool eyemDetectAndDecodeFree(IntPtr hObject);
EXPORTS int eyemCountObject(EyemImage tpImage, const char *fileName, double dOffset, int iMinArea, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg); EXPORTS int eyemCountObject(EyemImage tpImage, const char *fileName, double dOffset, int iMinArea, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, double dOffset, const char * ccSubType, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg); EXPORTS int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, double dOffset, const char * ccSubType, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg);
EXPORTS int eyemImageRead(const char *filename, int iFalgs, EyemImage *ucpImage);
EXPORTS int eyemImageMalloc(int iWidth, int iHeight, int iChannels, int ccType, EyemImage *tpImage);
EXPORTS int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, EyemImage *tpImage);
EXPORTS void eyemImageFree(void *ipImage);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
#include "eyemMisc.h" #include "eyemMisc.h"
int eyemImageRead(const char *filename, int iFlag, EyemImage *tpImage)
{
cv::Mat src = cv::imread(filename, iFlag);
if (src.empty())
return FUNC_IMAGE_NOT_EXIST;
//图像信息
int _X = src.cols, _Y = src.rows, _Depth = src.depth(), _Channels = src.channels();
//内存尺寸
int _Size = _X*_Y*_Channels;
switch (src.depth())
{
case CV_8U:
_Size *= sizeof(unsigned char);
tpImage->vpImage = (unsigned char *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_8S:
_Size *= sizeof(signed char);
tpImage->vpImage = (signed char *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_16U:
_Size *= sizeof(unsigned short);
tpImage->vpImage = (unsigned short *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_16S:
_Size *= sizeof(signed short);
tpImage->vpImage = (signed short *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_32S:
_Size *= sizeof(signed int);
tpImage->vpImage = (signed int *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_32F:
_Size *= sizeof(float);
tpImage->vpImage = (float *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_64F:
_Size *= sizeof(double);
tpImage->vpImage = (double *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
default:
//no support format
return FUNC_CANNOT_USE;
}
//图像信息
tpImage->iWidth = _X; tpImage->iHeight = _Y; tpImage->iDepth = _Depth; tpImage->iChannels = _Channels;
//拷贝数据
memcpy(tpImage->vpImage, src.data, _Size);
return FUNC_OK;
}
int eyemImageMalloc(int iWidth, int iHeight, int iChannels, int ccType, EyemImage *tpImage)
{
//内存尺寸
int _Size = iWidth*iHeight*iChannels;
switch (ccType)
{
case CV_8U:
tpImage->iDepth = 0;
_Size *= sizeof(unsigned char);
tpImage->vpImage = (unsigned char *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_8S:
tpImage->iDepth = 1;
_Size *= sizeof(signed char);
tpImage->vpImage = (signed char *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_16U:
tpImage->iDepth = 2;
_Size *= sizeof(unsigned short);
tpImage->vpImage = (unsigned short *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_16S:
tpImage->iDepth = 3;
_Size *= sizeof(signed short);
tpImage->vpImage = (signed short *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_32S:
tpImage->iDepth = 4;
_Size *= sizeof(signed int);
tpImage->vpImage = (signed int *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_32F:
tpImage->iDepth = 5;
_Size *= sizeof(float);
tpImage->vpImage = (float *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_64F:
tpImage->iDepth = 6;
_Size *= sizeof(double);
tpImage->vpImage = (double *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
default:
//no support format
return FUNC_CANNOT_USE;
}
//图像信息
tpImage->iWidth = iWidth; tpImage->iHeight = iHeight; tpImage->iChannels = iChannels;
return FUNC_OK;
}
int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, EyemImage *tpImage)
{
if (std::strlen(filename) == 0)
return FUNC_IMAGE_NOT_EXIST;
FILE *fp = fopen(filename, "rb+");
if (NULL != fp)
{
switch (iDepth)
{
case CV_8U:
tpImage->vpImage = (unsigned char *)malloc(iWidth*iHeight * sizeof(unsigned char));
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, iWidth*iHeight * sizeof(unsigned char));
fread(tpImage->vpImage, sizeof(unsigned char), iWidth*iHeight, fp);
break;
case CV_16U:
tpImage->vpImage = (unsigned short *)malloc(iWidth*iHeight * sizeof(unsigned short));
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, iWidth*iHeight * sizeof(unsigned short));
fread(tpImage->vpImage, sizeof(unsigned short), iWidth*iHeight, fp);
break;
default:
//不支持位深度
break;
}
}
else
return FUNC_IMAGE_NOT_EXIST;
return FUNC_OK;
}
static void drawLine(cv::InputOutputArray img, cv::Point pt1, cv::Point pt2, const cv::Scalar& color, int thickness, double tipLength, double trackLength, std::vector<cv::Point> &trackLine) static void drawLine(cv::InputOutputArray img, cv::Point pt1, cv::Point pt2, const cv::Scalar& color, int thickness, double tipLength, double trackLength, std::vector<cv::Point> &trackLine)
{ {
const double angle = atan2((double)pt1.y - pt2.y, (double)pt1.x - pt2.x); const double angle = atan2((double)pt1.y - pt2.y, (double)pt1.x - pt2.x);
...@@ -2909,8 +2733,4 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, doubl ...@@ -2909,8 +2733,4 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, doubl
return FUNC_OK; return FUNC_OK;
} }
void eyemImageFree(void *ucpImage)
{
// must be free
free(ucpImage);
}
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#ifndef __EYEM_MISC_H #ifndef __EYEM_MISC_H
#define __EYEM_MISC_H #define __EYEM_MISC_H
#include <omp.h>
#include <io.h> #include <io.h>
#include <direct.h> #include <direct.h>
#include "eyemLib.h" #include "eyemLib.h"
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!