Commit 547390fb 张士柳

1 个父辈 ae41cb88
......@@ -497,6 +497,5 @@ namespace eyemLib_Sharp
return tpImage;
}
#endregion
}
}
......@@ -24,7 +24,6 @@ namespace eyemLib_Sharp
{
EyemLib.eyemReadImageTool(item);
}
EyemLib.Free();
Console.Write("请按任意键继续。。。");
Console.ReadKey();
......
......@@ -8,44 +8,4 @@
#include "eyemLib.h"
typedef unsigned int CvLabel;
typedef std::map<CvLabel, cv::Scalar> Palete;
/// \def _HSV2RGB_(H, S, V, R, G, B)
/// \brief Color translation between HSV and RGB.
#define _HSV2RGB_(H, S, V, R, G, B) \
{ \
double _h = H/60.; \
int _hf = (int)floor(_h); \
int _hi = ((int)_h)%6; \
double _f = _h - _hf; \
\
double _p = V * (1. - S); \
double _q = V * (1. - _f * S); \
double _t = V * (1. - (1. - _f) * S); \
\
switch (_hi) \
{ \
case 0: \
R = 255.*V; G = 255.*_t; B = 255.*_p; \
break; \
case 1: \
R = 255.*_q; G = 255.*V; B = 255.*_p; \
break; \
case 2: \
R = 255.*_p; G = 255.*V; B = 255.*_t; \
break; \
case 3: \
R = 255.*_p; G = 255.*_q; B = 255.*V; \
break; \
case 4: \
R = 255.*_t; G = 255.*_p; B = 255.*V; \
break; \
case 5: \
R = 255.*V; G = 255.*_p; B = 255.*_q; \
break; \
} \
}
#endif/* __EYEM_BIN_H */
\ No newline at end of file
......@@ -54,26 +54,12 @@ void eyemClp2dLinePointAndSlope(EyemOcsDXY tpPoint, double dSlope, EyemOcsDABC &
int eyemClp2dIntersectionTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, EyemOcsDXY &tpPoint)
{
if (abs(tpLine1.dA*tpLine2.dB - tpLine2.dA*tpLine1.dB) < EPS) {
double det = tpLine1.dA*tpLine2.dB - tpLine2.dA*tpLine1.dB;
if (abs(det) < EPS) {
return FUNC_CANNOT_CALC;
}
//计算系数
double sa[4], sb[2], sx[2];
cv::Mat a = cv::Mat(2, 2, CV_64F, sa), b = cv::Mat(2, 1, CV_64F, sb);
//系数矩阵A*X=B;
cv::Mat x = cv::Mat(2, 1, CV_64F, sx);
std::memset(sa, 0, sizeof(sa));
std::memset(sb, 0, sizeof(sb));
std::memset(sx, 0, sizeof(sx));
sa[0] = tpLine1.dA, sa[1] = tpLine1.dB;
sa[2] = tpLine2.dA, sa[3] = tpLine2.dB;
sb[0] = -tpLine1.dC, sb[1] = -tpLine2.dC;
//solve
cv::solve(a, b, x, cv::DECOMP_SVD);
tpPoint.dX = sx[0];
tpPoint.dY = sx[1];
tpPoint.dX = (tpLine1.dB*tpLine2.dC - tpLine2.dB*tpLine1.dC) / det;
tpPoint.dY = (tpLine2.dA*tpLine1.dC - tpLine1.dA*tpLine2.dC) / det;
return FUNC_OK;
}
......
......@@ -102,6 +102,46 @@
typedef intptr_t IntPtr;
#endif
typedef unsigned int CvLabel;
typedef std::map<CvLabel, cv::Scalar> Palete;
/// \def _HSV2RGB_(H, S, V, R, G, B)
/// \brief Color translation between HSV and RGB.
#define _HSV2RGB_(H, S, V, R, G, B) \
{ \
double _h = H/60.; \
int _hf = (int)floor(_h); \
int _hi = ((int)_h)%6; \
double _f = _h - _hf; \
\
double _p = V * (1. - S); \
double _q = V * (1. - _f * S); \
double _t = V * (1. - (1. - _f) * S); \
\
switch (_hi) \
{ \
case 0: \
R = 255.*V; G = 255.*_t; B = 255.*_p; \
break; \
case 1: \
R = 255.*_q; G = 255.*V; B = 255.*_p; \
break; \
case 2: \
R = 255.*_p; G = 255.*V; B = 255.*_t; \
break; \
case 3: \
R = 255.*_p; G = 255.*_q; B = 255.*V; \
break; \
case 4: \
R = 255.*_t; G = 255.*_p; B = 255.*V; \
break; \
case 5: \
R = 255.*V; G = 255.*_p; B = 255.*_q; \
break; \
} \
}
// 图像边界处理
#ifndef __EYEM_BORDER
......@@ -149,6 +189,14 @@ typedef struct {
double dVar; // 可能会使用的值
} EyemRect3;
// 旋转矩形定义
typedef struct {
double dWidth; // 旋转矩形宽度
double dHeight; // 旋转矩形高度
double dAngle; // 旋转矩形角度(-90==>90)
EyemOcsDXY tC; // 旋转矩形中心
} EyemRotateRect;
///////////////////////////////////////////////////////////////////////////////
// Orthogonal Coordinate System
......@@ -621,6 +669,7 @@ extern "C" {
EXPORTS int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int iTransition, double dSigma, double dAmpThresh, IntPtr *hObject);
EXPORTS int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int iCapLength, int iCapWidth, int nCalipers, int nFilterSize, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject);
EXPORTS int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iCapLength, int iCapWidth, int nCalipers, int iFilterSize, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject);
EXPORTS int eyemEdge1dRidgeDetection(EyemImage tpImage);
EXPORTS bool eyemEdge1dGenMeasureFree(IntPtr hObject);
#ifdef __cplusplus
......
此文件类型无法预览
......@@ -182,6 +182,7 @@
<ClInclude Include="eyemSmooth.h" />
<ClInclude Include="eyemCodeDetector.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="stegers.h" />
<ClInclude Include="yoloWrapper.h" />
</ItemGroup>
<ItemGroup>
......@@ -205,6 +206,7 @@
<ClCompile Include="eyemSmooth.cpp" />
<ClCompile Include="eyemCodeDetector.cpp" />
<ClCompile Include="libopencv.cpp" />
<ClCompile Include="stegers.cpp" />
<ClCompile Include="yoloWrapper.cpp" />
</ItemGroup>
<ItemGroup>
......
......@@ -69,6 +69,9 @@
<ClInclude Include="eyemNNDetector.h">
<Filter>源文件</Filter>
</ClInclude>
<ClInclude Include="stegers.h">
<Filter>源文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="eyemLib.cpp">
......@@ -134,6 +137,9 @@
<ClCompile Include="eyemNNDetector.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="stegers.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="eyemLib.rc">
......
......@@ -617,6 +617,16 @@ int eyemDecompose(EyemImage tpImage, EyemImage *tpDstImgR, EyemImage *tpDstImgG,
return FUNC_OK;
}
int eyemCopyRegion(EyemImage tpImage, EyemRotateRect tpRoi, EyemImage *tpDstImg)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
return FUNC_OK;
}
int eyemNormalize(EyemImage &tpImage)
{
CV_Assert(NULL != tpImage.vpImage);
......
......@@ -5,6 +5,7 @@
#ifndef __EYEM_MISC_H
#define __EYEM_MISC_H
#include <numeric>
#include "eyemLib.h"
#include <tbb\tbb.h>
......
#include "stegers.h"
contour::contour() { clear(); }
//constructor
contour::contour(int32_t nnum, std::vector<float>& nrow, std::vector<float>& ncol, std::vector<float>& nangle, std::vector<float>& nresponse, contour_class ncont_class) {
num = nnum;
row = nrow;
col = ncol;
angle = nangle;
response = nresponse;
cont_class = ncont_class;
}
void contour::clear() {
num = 0;
row.resize(0);
col.resize(0);
angle.resize(0);
response.resize(0);
width_l.resize(0);
width_r.resize(0);
asymmetry.resize(0);
contrast.resize(0);
cont_class = contour_class::cont_no_junc;
}
chord::chord()
{
r = 0;
cb = 0;
ce = 0;
}
chord::chord(short nr, short ncb, short nce)
{
r = nr;
cb = ncb;
ce = nce;
}
region::region(const std::vector<int32_t>& image, uint32_t min_val,
int32_t image_width, int32_t image_m_height) {
rl.resize(0);
long grey;
long r, c, l, count;
bool inside;
inside = false;
count = 0;
rl.emplace_back();
for (r = 0; r < image_m_height; r++) {
for (c = 0; c < image_width; c++) {
l = LCOR(r, c, image_width);
grey = image[l];
if (grey >= min_val) {
if (!inside) {
inside = true;
rl[count].r = (int16_t)r;
rl[count].cb = (int16_t)c;
}
}
else {
if (inside) {
inside = false;
rl[count].ce = (int16_t)(c - 1);
count++;
rl.emplace_back();
}
}
}
if (inside) {
inside = false;
rl[count].ce = (int16_t)(image_width - 1);
count++;
rl.emplace_back();
}
}
this->num = count;
}
//
//bool region::test() {
// const char* frame[] =
// {
// "00100100",
// "00110100",
// "00011000",
// "01000100",
// "01000000",
// 0 };
// const char* gold[] =
// {
// "00100100",
// "00110100",
// "00011000",
// "02000100",
// "02000000",
// 0 };
//
// cv::Mat pels(5, 8, CV_8U);
// DrawShape(pels, frame);
//
// std::vector<int32_t> lpels(5 * 8);
// for (auto row = 0; row < pels.rows; row++)
// for (auto col = 0; col < pels.cols; col++) {
// auto l = LCOR(row, col, pels.cols);
// lpels[l] = int32_t(pels.at<uint8_t>(row, col));
// }
//
// region rg(lpels, 1, pels.cols, pels.rows);
// bool check = rg.rl.size() == 9;
// if (!check) return check;
//
// std::vector<chord> golds;
// golds.emplace_back(0, 2, 2);
// golds.emplace_back(0, 5, 5);
// golds.emplace_back(1, 2, 3);
// golds.emplace_back(1, 5, 5);
// golds.emplace_back(2, 3, 4);
// golds.emplace_back(3, 1, 1);
// golds.emplace_back(3, 5, 5);
// golds.emplace_back(4, 1, 1);
// golds.emplace_back(0, 0, 0);
//
// for (int i = 0; i < 9; i++)
// assert(rg.rl[i] == golds[i]);
//
// return true;
//}
\ No newline at end of file
#pragma once
#include <vector>
#include <ostream>
#ifndef LCOR
#define LCOR(row,col,width) (row)*(width) + (col)
#endif
enum class contour_class
{
/** no end point is a junction */
cont_no_junc,
/** only the start point of the line is a junction */
cont_start_junc,
/** only the end point of the line is a junction */
cont_end_junc,
/** both end points of the line are junctions */
cont_both_junc,
/** the contour is closed */
cont_closed
};
class contour
{
/** number of points */
public:
//default constructor
contour();
//constructor
contour(int32_t nnum, std::vector<float>& nrow, std::vector<float>& ncol, std::vector<float>& nangle, std::vector<float>& nresponse, contour_class ncont_class);
void clear();
float compute_length() const {
std::vector<float>::const_iterator row_b = row.begin() + 1;
std::vector<float>::const_iterator col_b = col.begin() + 1;
float length = 0.0f;
for (; row_b < row.end() && col_b < col.end(); row_b++, col_b++) {
float dr = *(row_b)-*(row_b - 1);
float dc = *(col_b)-*(col_b - 1);
length += std::sqrt(dr * dr + dc * dc);
}
return length;
}
int32_t num = 0;
std::vector<float> row;
/** column coordinates of the line points (X coordinate in ImageJ) */
std::vector<float> col;
/** angle of normal (measured from the row (Y) axis) */
std::vector<float> angle;
/** response of line point (second derivative) */
std::vector<float> response;
/** width to the left of the line */
std::vector<float> width_l;
/** width to the right of the line */
std::vector<float> width_r;
/** asymmetry of the line point */
std::vector<float> asymmetry;
/** contrast of the line point */
std::vector<float> contrast;
/** contour class (e.g., closed, no_junc) */
contour_class cont_class;
};
class crossRef {
public:
/*
Storage the Crossref variables, it is the Correction.java code
This data structure facilitates the quick search for the next possible starting point of a line.An array of crossrefs will be accumulatedand
sorted according to its value.xand y are the coordinates of a point in the image.When this point has been processed it will be marked as done.
*/
crossRef(int32_t x = 0, int32_t y = 0, double value = 0.0, bool done = false) : m_x(x), m_y(y), m_val(value), m_done(done) {}
// Accessors
const int32_t& x() const { return m_x; }
const int32_t& y() const { return m_y; }
const double& value() const { return m_val; }
bool done() const { return m_done; }
void setDone() const { m_done = true; }
void setUnDone() const { m_done = false; }
int32_t compareTo(crossRef& other) {
int32_t rt = (m_val > other.value()) ? -1 : (m_val < other.value()) ? 1 : 0;
return rt;
}
bool operator==(const crossRef& other) const {
return this->m_val == other.value();
}
bool operator<(const crossRef& other) const {
return this->m_val < other.value();
}
bool operator>(const crossRef& other) const {
return this->m_val > other.value();
}
friend std::ostream& operator<< (std::ostream& ous, const crossRef& dis)
{
// return + str(self.x) + + str(self.y) + + str(self.value) + + str(self.done)
ous << "x: " << dis.x() << "\ty: " << dis.y() << "\tvalue: " << dis.value() << "\tdone: " << std::boolalpha << dis.done();
return ous;
}
private:
int32_t m_x, m_y;
double m_val;
mutable bool m_done;
};
/** Data structure to store three doubles: x,y and t (distance along line) */
class doublepoint
{
public:
double cx = 0;
double cy = 0;
double t = 0;
doublepoint() {}
doublepoint(double ccx, double ccy, double ct) {
cx = ccx;
cy = ccy;
t = ct;
}
doublepoint(double ccx, double ccy) {
cx = ccx;
cy = ccy;
t = 0;
}
};
/** Offsets to a specific location in the image. An array of this type is
returned by the modified Bresenham algorithm in width.c. It is also used
in link.c to hold an array of pixel locations to check for appropriate
neighbors. */
class offset
{
public:
int32_t x;
int32_t y;
offset() { x = 0; y = 0; }
offset(int32_t nx, int32_t ny) {
x = nx;
y = ny;
}
};
/** This data structure is used to accumulate junction information. It is
needed to split lines at junction points. */
class junction
{
/** Index of line that is already processed */
public:
int32_t cont1 = 0;
/** Index of line that runs into cont1 */
int32_t cont2 = 0;
/** Index of the junction point in cont1 */
int32_t pos = 0;
/** y-(row-)coordinate of the junction point (corrected for ImageJ)*/
float x = 0;
/** x-(col-)coordinate of the junction point (corrected for ImageJ)*/
float y = 0;
junction() {}
junction(int32_t ncont1, int32_t ncont2, int32_t npos, float nx, float ny) {
cont1 = ncont1;
cont2 = ncont2;
pos = npos;
x = nx;
y = ny;
}
bool operator==(const junction& other) const {
return this->pos == other.pos;
}
bool operator<(const junction& other) const {
return this->pos < other.pos;
}
bool operator>(const junction& other) const {
return this->pos > other.pos;
}
/** This function compares two junctions according to their first line indexes,
and, if needed, by the position of the junction within the line. It is
called by qsort. */
static bool compare(const junction& thisJunction, const junction& otherjunction) {
if (thisJunction.cont1 == otherjunction.cont1)
{
return thisJunction.pos >= otherjunction.pos;
}
else
{
return thisJunction.cont1 > otherjunction.cont1;
}
}
friend std::ostream& operator<< (std::ostream& ous, const junction& dis)
{
ous << "cont1: " << dis.cont1 << "\tcont2: " << dis.cont2 << "\tpos: " << dis.pos << "\txy: " << dis.x << "," << dis.y;
return ous;
}
};
/** A chord in a run-length encoded region */
class chord
{
/** row coordinate of the chord */
public:
// default dtor, copy ctor ok
short r = 0;
/** column coordinate of the start of the chord */
short cb = 0;
/** column coordinate of the end of the chord */
short ce = 0;
chord();
chord(short nr, short ncb, short nce);
bool operator==(chord& other) const {
return this->r == other.r && this->cb == other.cb && this->ce == other.ce;
}
};
/** Run-length encoded region of an image. This type is returned by the
threshold() function. It provides the means to efficiently link line points
into lines. */
class region
{
public:
region(const std::vector<int32_t>& image, uint32_t min_val,
int32_t image_width, int32_t image_m_height);
int32_t num = 0; // number of chords
std::vector<chord> rl; // array of chords
//static bool test();
};
\ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!