Commit 6cf73433 张士柳

1 个父辈 2fc4e743
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections.Generic;
using System.Runtime.InteropServices;
#region 结构体
// 图像信息
[StructLayout(LayoutKind.Sequential)]
public struct EyemImage
{
public IntPtr vpImage; // 地址
public int iWidth; // 图像内存 x 方向大小
public int iHeight; // 图像内存 y 方向大小
public int iDepth; // 图像位深度(详见说明)
public int iChannels; // 图像通道数
}
// 矩形定义
[StructLayout(LayoutKind.Sequential)]
public struct EyemRect
{
public int iXs; // 起始点(左上角) x 坐标
public int iYs; // 起始点(左上角) y 坐标
public int iWidth; // x 方向大小(宽度)
public int iHeight; // y 方向大小(高度)
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemRect2
{
public int iXs; // 起始点(左上角) x 坐标
public int iYs; // 起始点(左上角) y 坐标
public int iXe; // 端点(右下) x 坐标
public int iYe; // 端点(右下) y 坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemRect3
{
public int iXs; // 起始点(左上角) x 坐标
public int iYs; // 起始点(左上角) y 坐标
public int iWidth; // x 方向大小(宽度)
public int iHeight; // y 方向大小(高度)
public double dVar; // 某种可能会使用的值
}
[StructLayout(LayoutKind.Sequential)]
public struct BboxContainer
{
//最多支持100个目标
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
public EyemRect[] bboxes;
}
///////////////////////////////////////////////////////////////////////////////
// Orthogonal Coordinate System
/////////////////////
// int type
//
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIXY
{
public int iX; // X坐标
public int iY; // Y坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIXYZ
{
public int iX; // X坐标
public int iY; // Y坐标
public int iZ; // Z坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIXYQ
{
public int iX; // X坐标
public int iY; // Y坐标
public int iQ; // θ
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIXYR // 用于表示圆
{
public int iX; // X坐标
public int iY; // Y坐标
public int iR; // 半径
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIABC // 用于表示直线(一般形式)
{
public int iA; // a
public int iB; // b
public int iC; // c
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIRQ // 用于表示直线(黑森标准形式)或矢量
{
public int iR; // ρ
public int iQ; // θ
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIXYQS
{
public int iX; // X坐标(单位:像素)
public int iY; // Y坐标(单位:像素)
public int iQ; // 斜率(単位:rad)
public int iS; // 刻度
}
/////////////////////
// float type
//
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFXY
{
public float fX; // X坐标
public float fY; // Y坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFXYZ
{
public float fX; // X坐标
public float fY; // Y坐标
public float fZ; // Z坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFXYQ
{
public float fX; // X坐标
public float fY; // Y坐标
public float fQ; // θ
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFXYR // 用于表示圆
{
public float fX; // X坐标
public float fY; // Y坐标
public float fR; // 半径
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFABC // 用于表示直线(一般形式)
{
public float fA; // a
public float fB; // b
public float fC; // c
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFRQ // 用于表示直线(黑森标准形式)或矢量
{
public float fR; // ρ
public float fQ; // θ
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFXYQS
{
public float fX; // X坐标(単位:像素)
public float fY; // Y坐标(単位:像素)
public float fQ; // 斜率(単位:rad)
public float fS; // 刻度
}
/////////////////////
// double type
//
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDXY
{
public double dX; // X坐标
public double dY; // Y坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDXYZ
{
public double dX; // X坐标
public double dY; // Y坐标
public double dZ; // Z坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDXYQ
{
public double dX; // X坐标
public double dY; // Y坐标
public double dQ; // θ
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDXYR // 用于表示圆
{
public double dX; // 中心的X坐标
public double dY; // 中心的Y坐标
public double dR; // 半径
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDABC // 直线(一般形)的表现形式
{
public double dA; // a
public double dB; // b
public double dC; // c
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDRQ // 用于表示直线(黑森标准形状)和矢量
{
public double dR; // ρ
public double dQ; // θ
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDXYQS
{
public double dX; // X坐标
public double dY; // Y坐标
public double dQ; // 旋转角度(単位:rad)
public double dS; // 规模
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDABCD // 用于表示平面(一般形式)
{
public double dA; // a
public double dB; // b
public double dC; // c
public double dD; // d
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDXYLSQ // 用于表示椭圆
{
public double dXo; // 中心X坐标
public double dYo; // 中心Y坐标
public double dL; // 长轴半径
public double dS; // 短轴半径
public double dQ; // 长轴倾斜角(単位:rad)
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDPV // 用于表示三维空间中的直线
{
public EyemOcsDXYZ tP; // 直线上一点的坐标
public EyemOcsDXYZ tV; // 直线方向矢量
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDCRUVW // 用于表示椭圆体
{
public EyemOcsDXYZ tC; // 椭圆体中心
public EyemOcsDXYZ tR; // 轴半径(dX:长轴、dY:中轴、dZ:短轴)
public double dU; // 长轴投影到 XY 平面与 X 轴的角(单位:rad)
public double dV; // 长轴与XY平面之角(单位:rad)
public double dW; // 绕长轴旋转角度(单位:rad)
}
// Blob 分析结果
[StructLayout(LayoutKind.Sequential)]
public struct EyemBinBlob
{
public int iLabel; // 标签
public int iArea; // 面积
public double dCenterX; // 重心x坐标
public double dCenterY; // 重心y坐标
public int iXs, iYs, iXe, iYe; // 外接矩形(始点,终点)
public int iWidth, iHeight; // 外接矩形(x 方向大小(宽度),y 方向大小(高度))
public double dTheta; // 主轴倾斜角(rad)
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemChainCode
{
public int iLabel; // 标签
public double dX; // x坐标
public double dY; // y坐标
public double dVx, dVy; // 向量
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemBlobParams
{
// public bool isLight;
public bool filterByArea; //斑点大小限制
public int minArea, maxArea; //最小面积/最大面积
public bool filterByCircularity; //斑点圆度限制
public float minCircularity, maxCircularity; //圆度最小/大限制
public bool filterByInertia; //斑点的惯性率限制
public float minInertiaRatio, maxInertiaRatio; //惯性率最小/大限制
public bool filterByConvexity; //斑点凸度限制
public float minConvexity, maxConvexity; //凸度最小/大限制
}
// 条码 解码结果
[StructLayout(LayoutKind.Sequential)]
public struct EyemBarCode
{
public double dAngle; // 角度
public int iCenterX; // x坐标
public int iCenterY; // y坐标
public IntPtr hType; // 码类型
public IntPtr hText; // 码内容
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemModelID
{
public IntPtr vpImage; // 地址
public int iXs; // 图像X坐标
public int iYs; // 图像Y坐标
public int iWidth; // 图像内存X方向大小
public int iHeight; // 图像内存Y方向大小
public double dMatchDeg; // 匹配度
public IntPtr lpszName; // 名称
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemRigidMatrix
{
public double a00; // a00
public double a01; // a01
public double b00; // b00
public double a10; // a10
public double a11; // a11
public double b10; // b10
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemHSVModel
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public double[] dpRangeL, dpRangeU; // 提取下限,提取上限[H S V]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public double[] dpRangeLExt, dpRangeUExt; // 额外提取下限,额外提取上限(针对处于跨模型颜色,比如红色)[H S V]
}// 用于HSV颜色模型分割(H(0-180)、S(0-255)、V(0-255))
[StructLayout(LayoutKind.Sequential)]
public struct EyemTargetMatch
{
public float fCenterX;
public float fCenterY;
public float fMatchScore;
public float fMatchAngle;
}
#endregion
#region 枚举
//图像格式转换信息
enum ColorConversionCodes
{
COLOR_BGR2BGRA = 0, //!< add alpha channel to RGB or BGR image
COLOR_RGB2RGBA = COLOR_BGR2BGRA,
COLOR_BGRA2BGR = 1, //!< remove alpha channel from RGB or BGR image
COLOR_RGBA2RGB = COLOR_BGRA2BGR,
COLOR_BGR2RGBA = 2, //!< convert between RGB and BGR color spaces (with or without alpha channel)
COLOR_RGB2BGRA = COLOR_BGR2RGBA,
COLOR_RGBA2BGR = 3,
COLOR_BGRA2RGB = COLOR_RGBA2BGR,
COLOR_BGR2RGB = 4,
COLOR_RGB2BGR = COLOR_BGR2RGB,
COLOR_BGRA2RGBA = 5,
COLOR_RGBA2BGRA = COLOR_BGRA2RGBA,
COLOR_BGR2GRAY = 6, //!< convert between RGB/BGR and grayscale, @ref color_convert_rgb_gray "color conversions"
COLOR_RGB2GRAY = 7,
COLOR_GRAY2BGR = 8,
COLOR_GRAY2RGB = COLOR_GRAY2BGR,
COLOR_GRAY2BGRA = 9,
COLOR_GRAY2RGBA = COLOR_GRAY2BGRA,
COLOR_BGRA2GRAY = 10,
COLOR_RGBA2GRAY = 11,
COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions"
COLOR_RGB2HSV = 41,
COLOR_HSV2BGR = 54, //!< backward conversions to RGB/BGR
COLOR_HSV2RGB = 55,
};
#endregion
public unsafe class EyemLibDotNet
{
#region 通用
/// <summary>
/// Win32 memory copy function
/// </summary>
/// <param name="dst">目标地址</param>
/// <param name="src">源地址</param>
/// <param name="count">长度</param>
/// <returns></returns>
[DllImport("ntdll.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern byte* memcpy(byte* dst, byte* src, int count);
/// <summary>
/// 从进程中的非托管内存分配指定长度的内存
/// </summary>
/// <param name="cb">长度</param>
/// <returns>地址</returns>
[DllImport("eyemLib.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr eyemMallocMemBlock(int cb);
/// <summary>
/// 释放从非托管内存中分配的内存
/// </summary>
/// <param name="block">地址</param>
[DllImport("eyemLib.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemFreeMemBlock(IntPtr block);
/// <summary>
/// 读取图像文件
/// </summary>
/// <param name="filename">文件名</param>
/// <param name="iFlags">读取标志,-1:按照原样加载图像 0:始终将图像转化成单通道灰度图像 1:如果设置,请始终将图像转换为3通道BGR彩色图像
/// 2:在输入具有相应深度时返回16位/32位图像,否则将其转换为8位 4:以任何可能的颜色格式读取图像 </param>
/// <param name="tpImage">图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemImageRead(string filename, int iFlags, out EyemImage tpImage);
/// <summary>
/// 释放图像资源
/// </summary>
/// <param name="tpImage">图像</param>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemImageFree(ref EyemImage tpImage);
#endregion
#region 2值化
/// <summary>
/// 自适应二值化图像
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="dSigma">sigma</param>
/// <param name="iLightDark">二值化形式</param>
/// <param name="binMethod">二值化方法</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBinAutoThreshold(EyemImage tpImage, double dSigma, int iLightDark, int binMethod, out EyemImage tpDstImg);
/// <summary>
/// 全局二值化
/// </summary>
/// <param name="tpSrcImg">原图</param>
/// <param name="iLightDark">黑白</param>
/// <param name="dThresh">阈值</param>
/// <param name="dMaxVal">最大值</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double dMaxVal, out EyemImage tpDstImg);
/// <summary>
/// 彩色图像分割
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="ipRangeL">下限[0,0,0]</param>
/// <param name="ipRangeU">上限[255,255,255]</param>
/// <param name="tpDstImg">结果</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBinThresholdC(EyemImage tpImage, EyemHSVModel tpHSVModel, out EyemImage tpDstImg);
/// <summary>
/// 局部自适应二值化
/// </summary>
/// <param name="tpSrcImg">图像</param>
/// <param name="iLightDark">二值化类型</param>
/// <param name="iWinSize">窗口大小</param>
/// <param name="dK">补偿</param>
/// <param name="binarizationMethod">二值化方法</param>
/// <param name="dR">半径</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBinNiBlack(EyemImage tpSrcImg, int iLightDark, int iWinSize, double dK, int binarizationMethod, double dR, out EyemImage tpDstImg);
/// <summary>
/// 动态阈值
/// </summary>
/// <param name="tpSrcImg">图像</param>
/// <param name="tpThresholdImg">处理后图像(一般为滤波后图像)</param>
/// <param name="iOffset">补偿</param>
/// <param name="iLightDark">二值化形式</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpThresholdImg, double iOffset, int iLightDark, out EyemImage tpDstImg);
#endregion
#region 矩阵运算
/// <summary>
/// 分配创建图像
/// </summary>
/// <param name="iWidth">图像宽度</param>
/// <param name="iHeight">图像高度</param>
/// <param name="iChannels">通道数</param>
/// <param name="ccSubType">数据类型(uint8_t、int8_t、uint16_t、int16_t、int32_t、float_t、double_t)</param>
/// <param name="tpImage">图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMatMalloc(int iWidth, int iHeight, int iChannels, string ccSubType, out EyemImage tpImage);
/// <summary>
/// 拷贝图像
/// </summary>
/// <param name="tpDstImg">目标图像</param>
/// <param name="tpImage">源图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMatCopy(ref EyemImage tpDstImg, EyemImage tpImage);
/// <summary>
/// 图像颜色空间转换
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="iCCodes">转换代码</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCvtImageColor(EyemImage tpImage, ColorConversionCodes iCCodes, ref EyemImage tpDstImg);
/// <summary>
/// 图像数据格式转换
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="ccSubType">转换类型(uint8_t、int8_t、uint16_t、int16_t、int32_t、float_t、double_t)</param>
/// <param name="alpha">乘值,1.0</param>
/// <param name="beta">加值,0.0</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCvtImageType(EyemImage tpImage, string ccSubType, double alpha, double beta, ref EyemImage tpDstImg);
/// <summary>
/// 拷贝指定位置的图像
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="tpRoi">位置</param>
/// <param name="tpDstImg">结果</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCopyRegion(EyemImage tpImage, EyemRect tpRoi, out EyemImage tpDstImg);
/// <summary>
/// 统计非零像素数量
/// </summary>
/// <param name="tpImage">图像</param>
/// <returns>结果</returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountNonZero(EyemImage tpImage);
#endregion
#region EyemImageBitmap相互转换
public static Bitmap eyemCvtToBitmap(EyemImage tpImage)
{
if (tpImage.vpImage == IntPtr.Zero || tpImage.iDepth != 0)
return null;
PixelFormat format;
switch (tpImage.iChannels)
{
case 1:
format = PixelFormat.Format8bppIndexed;
break;
case 3:
format = PixelFormat.Format24bppRgb;
break;
case 4:
format = PixelFormat.Format32bppArgb;
break;
default:
return null;
}
Bitmap bitmap = new Bitmap(tpImage.iWidth, tpImage.iHeight, format);
//对于输出灰度图像
if (format == PixelFormat.Format8bppIndexed)
{
ColorPalette palette = bitmap.Palette;
for (int i = 0; i < 256; i++)
{
palette.Entries[i] = Color.FromArgb(i, i, i);
}
bitmap.Palette = palette;
}
//锁定数据区
BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, tpImage.iWidth, tpImage.iHeight),
ImageLockMode.WriteOnly, format);
try
{
int pd = ((tpImage.iWidth * tpImage.iChannels) + 3) / 4 * 4;
long bytesToCopy = tpImage.iWidth * tpImage.iChannels;
for (int y = 0; y < tpImage.iHeight; y++)
{
long offsetSrc = (y * tpImage.iWidth * tpImage.iChannels);
long offsetDst = (y * pd);
Buffer.MemoryCopy((byte*)(tpImage.vpImage.ToPointer()) + offsetSrc, (byte*)(bd.Scan0.ToPointer()) + offsetDst, bytesToCopy, bytesToCopy);
}
}
finally
{
bitmap.UnlockBits(bd);
}
return bitmap;
}
/// <summary>
/// Bitmap转EyemImage(需单独释放)
/// </summary>
/// <param name="bitmap"></param>
/// <returns></returns>
public static EyemImage eyemCvtToEyemImage(Bitmap bitmap)
{
EyemImage tpImage = new EyemImage();
//锁定数据区
BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly, bitmap.PixelFormat);
switch (bitmap.PixelFormat)
{
case PixelFormat.Format8bppIndexed:
tpImage.iChannels = 1;
break;
case PixelFormat.Format24bppRgb:
tpImage.iChannels = 3;
break;
case PixelFormat.Format32bppArgb:
tpImage.iChannels = 4;
break;
default:
throw new Exception("Image formats are not supported");
}
//仅支持8位
tpImage.iDepth = 0;
//图像尺寸
tpImage.iWidth = bitmap.Width; tpImage.iHeight = bitmap.Height;
//分配内存(释放不是用eyemImageFree,用Marshal.FreeHGlobal(tpImage.vpImage)),谁分配谁释放
tpImage.vpImage = Marshal.AllocHGlobal(bd.Stride * bd.Height);
try
{
int pd = ((tpImage.iWidth * tpImage.iChannels) + 3) / 4 * 4;
long bytesToCopy = tpImage.iWidth * tpImage.iChannels;
for (int y = 0; y < tpImage.iHeight; y++)
{
long offsetSrc = y * pd;
long offsetDst = y * tpImage.iWidth * tpImage.iChannels;
Buffer.MemoryCopy((byte*)(bd.Scan0.ToPointer()) + offsetSrc, (byte*)(tpImage.vpImage.ToPointer()) + offsetDst, bytesToCopy, bytesToCopy);
}
}
finally
{
bitmap.UnlockBits(bd);
}
return tpImage;
}
/// <summary>
/// Bitmap转EyemImage(可由eyemImageFree释放)
/// </summary>
/// <param name="bitmap"></param>
/// <returns></returns>
public static EyemImage eyemCvtToEyemImage2(Bitmap bitmap)
{
EyemImage tpImage = new EyemImage();
//锁定数据区
BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly, bitmap.PixelFormat);
switch (bitmap.PixelFormat)
{
case PixelFormat.Format8bppIndexed:
tpImage.iChannels = 1;
break;
case PixelFormat.Format24bppRgb:
tpImage.iChannels = 3;
break;
case PixelFormat.Format32bppArgb:
tpImage.iChannels = 4;
break;
default:
throw new Exception("Image formats are not supported");
}
//仅支持8位
tpImage.iDepth = 0;
//图像尺寸
tpImage.iWidth = bitmap.Width; tpImage.iHeight = bitmap.Height;
//分配内存(可由自带释放)
tpImage.vpImage = eyemMallocMemBlock(bd.Stride * bd.Height);
try
{
int pd = ((tpImage.iWidth * tpImage.iChannels) + 3) / 4 * 4;
long bytesToCopy = tpImage.iWidth * tpImage.iChannels;
for (int y = 0; y < tpImage.iHeight; y++)
{
long offsetSrc = y * pd;
long offsetDst = y * tpImage.iWidth * tpImage.iChannels;
Buffer.MemoryCopy((byte*)(bd.Scan0.ToPointer()) + offsetSrc, (byte*)(tpImage.vpImage.ToPointer()) + offsetDst, bytesToCopy, bytesToCopy);
}
}
finally
{
bitmap.UnlockBits(bd);
}
return tpImage;
}
#endregion
#region 结构体数组与内存指针相互转换
public static IntPtr eyemStructArray2IntPtr<T>(T[] tpArray)
{
if (tpArray == null)
throw new ArgumentNullException(typeof(T).Name.ToString());
//分配结构体需要的内存,需要释放
IntPtr hGlobal = Marshal.AllocHGlobal(checked(Marshal.SizeOf(typeof(T)) * tpArray.Length));
for (int index = 0; index < tpArray.Length; index++)
{
Marshal.StructureToPtr(tpArray[index], (IntPtr)(checked((long)hGlobal + index * Marshal.SizeOf(typeof(T)))), false);
}
return hGlobal;
}
public static List<T> eyemIntPtr2StructArray<T>(IntPtr hGlobal, int Size)
{
if (hGlobal == IntPtr.Zero)
throw new ArgumentNullException(typeof(IntPtr).Name.ToString());
//
List<T> tpArray = new List<T>();
for (int index = 0; index < Size; index++)
{
IntPtr lpArray = new IntPtr(checked(hGlobal.ToInt64() + index * Marshal.SizeOf(typeof(T))));
var structure = Marshal.PtrToStructure<T>(lpArray);
tpArray.Add(structure);
}
return tpArray;
}
#endregion
#region 项目 随项目改变添加
#endregion
}
\ No newline at end of file
......@@ -484,7 +484,7 @@ namespace eyemLib_Sharp
/// 读取图像文件
/// </summary>
/// <param name="filename">文件名</param>
/// <param name="iFlsgs">读取标志,-1:按照原样加载图像 0:始终将图像转化成单通道灰度图像 1:如果设置,请始终将图像转换为3通道BGR彩色图像
/// <param name="iFlags">读取标志,-1:按照原样加载图像 0:始终将图像转化成单通道灰度图像 1:如果设置,请始终将图像转换为3通道BGR彩色图像
/// 2:在输入具有相应深度时返回16位/32位图像,否则将其转换为8位 4:以任何可能的颜色格式读取图像 </param>
/// <param name="tpImage">图像</param>
/// <returns></returns>
......@@ -539,6 +539,9 @@ namespace eyemLib_Sharp
// 设定日志回调
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void setLogCallback(TCallBack cb);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemDrawHistogramImage(EyemImage tpImage, out EyemImage tpDstImg, [MarshalAs(UnmanagedType.LPArray)] int[] color, [MarshalAs(UnmanagedType.LPArray)] int[] mean_color, bool isDrawGrid, bool isDrawStats, int normValue);
#endregion
#region 滤波
......@@ -718,6 +721,19 @@ namespace eyemLib_Sharp
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAffineTransform(EyemImage tpImage, double tAngle, EyemOcsDXY tpCenter, out EyemImage tpDstImg);
//图像偏移
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemWarpShiftSubpix(EyemImage tpImage, double dShiftX, double dShiftY, out EyemImage tpDstImg, int iInterMethod = 1);
//拷贝指定位置的图像
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCopyRegion(EyemImage tpImage, EyemRect tpRoi, out EyemImage tpDstImg);
//统计非零像素数量
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountNonZero(EyemImage tpImage);
#endregion
#region 一维边缘测量
......@@ -845,7 +861,7 @@ namespace eyemLib_Sharp
/// <param name="tpResult">结果</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemFitRTMatrix(int iPtnNum, IntPtr taPointA, IntPtr taPointB, ref EyemRigidMatrix tpResult);
private static extern int eyemFitRTMatrix(int iPtnNum, bool bFullAffine, IntPtr taPointA, IntPtr taPointB, ref EyemRigidMatrix tpResult);
/// <summary>
/// 鲁棒椭圆拟合
......@@ -1050,7 +1066,7 @@ namespace eyemLib_Sharp
/// <param name="fFeatures">特征</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemExtractWithONNX(EyemImage tpImage, [MarshalAs(UnmanagedType.LPArray)]float[] fFeatures);
private static extern int eyemExtractWithONNX(EyemImage tpImage, [MarshalAs(UnmanagedType.LPArray)] float[] fFeatures);
#endregion
#region 模板匹配
......@@ -1063,7 +1079,7 @@ namespace eyemLib_Sharp
private static extern int eyemMakeNCCModel(EyemImage tpImage, int iiMinReduceArea);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemFindNCCModel(EyemImage tpImage, double dToleranceAngle, int iNumMatches, double dMaxOverlap, double dScore, IntPtr tpResults);
private static extern int eyemFindNCCModel(EyemImage tpImage, double dToleranceAngle, int iNumMatches, double dMaxOverlap, double dScore, bool bDrawResult, IntPtr tpResults, out EyemImage tpDstImg);
#endregion
#region 项目
......@@ -1072,23 +1088,23 @@ namespace eyemLib_Sharp
private static extern int eyemInitCounter(string extractorModelPath);
//普通器件(仍采用旧的算法)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObject(EyemImage tpImage, EyemRect tpRoi, string fileName, [MarshalAs(UnmanagedType.LPArray)]int[] ipReelNum, out EyemImage tpDstImg);
private static extern int eyemCountObject(EyemImage tpImage, EyemRect tpRoi, string fileName, [MarshalAs(UnmanagedType.LPArray)] int[] ipReelNum, out EyemImage tpDstImg);
//异型器件(新版本新算法)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, string fileName, string strType, [MarshalAs(UnmanagedType.LPArray)]int[] ipReelNum, out EyemImage tpDstImg);
private static extern int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, string fileName, string strType, [MarshalAs(UnmanagedType.LPArray)] int[] ipReelNum, out EyemImage tpDstImg);
//普通器件(新版本新算法)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, string fileName, [MarshalAs(UnmanagedType.LPArray)]int[] ipReelNum, out EyemImage tpDstImg);
private static extern int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, string fileName, [MarshalAs(UnmanagedType.LPArray)] int[] ipReelNum, out EyemImage tpDstImg);
//异型器件(新版本模板匹配)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, string fileName, string ccTplName, IntPtr hModelID, [MarshalAs(UnmanagedType.LPArray)]int[] ipReelNum, out EyemImage tpDstImg);
private static extern int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, string fileName, string ccTplName, IntPtr hModelID, [MarshalAs(UnmanagedType.LPArray)] int[] ipReelNum, out EyemImage tpDstImg);
//多选项异型件
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObjectIrregularPartsMultiopt(EyemImage tpImage, EyemRect tpRoi, int[] iOptions, [MarshalAs(UnmanagedType.LPArray)]int[] ipReelNum, out EyemImage tpDstImg);
private static extern int eyemCountObjectIrregularPartsMultiopt(EyemImage tpImage, EyemRect tpRoi, int[] iOptions, [MarshalAs(UnmanagedType.LPArray)] int[] ipReelNum, out EyemImage tpDstImg);
//普通器件(深度学习分割)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObjectUseNN(EyemImage tpImage, EyemRect tpRoi, string fileName, [MarshalAs(UnmanagedType.LPArray)]int[] ipReelNum, out EyemImage tpDstImg);
private static extern int eyemCountObjectUseNN(EyemImage tpImage, EyemRect tpRoi, string fileName, [MarshalAs(UnmanagedType.LPArray)] int[] ipReelNum, out EyemImage tpDstImg);
//匹配元件
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
......@@ -1134,10 +1150,10 @@ namespace eyemLib_Sharp
private static extern int eyemInitNNDataCodeModel(string detectorConfigPath, string detectorModelPath, string superResolutionConfigPath, string superResolutionModelPath);
//背景变化跟踪
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemTrackFeature(EyemImage tpImage, EyemImage tpMask, EyemRect tpRoi, IntPtr tpRois, int ipRoiNum, EyemHSVModel tpHSVModel, [MarshalAs(UnmanagedType.LPArray)]int[] ipResults, out EyemImage tpDstImg);
private static extern int eyemTrackFeature(EyemImage tpImage, EyemImage tpMask, EyemRect tpRoi, IntPtr tpRois, int ipRoiNum, EyemHSVModel tpHSVModel, [MarshalAs(UnmanagedType.LPArray)] int[] ipResults, out EyemImage tpDstImg);
//插件机
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, IntPtr tpArray, int iArraySize);
private static extern int eyemAOIPreprocessingForTSAV(EyemImage tpImage, EyemRect tpRoi, out EyemImage tpDstImg);
//跳过程序执行
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int setSkipProcessID(int pid);
......@@ -1171,7 +1187,7 @@ namespace eyemLib_Sharp
private static extern int eyemBuildTrainFile(string filePath, string fileName, bool shuffle = true);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern float calcSimilarity([MarshalAs(UnmanagedType.LPArray)]float[] lhs, [MarshalAs(UnmanagedType.LPArray)]float[] rhs);
private static extern float calcSimilarity([MarshalAs(UnmanagedType.LPArray)] float[] lhs, [MarshalAs(UnmanagedType.LPArray)] float[] rhs);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
......@@ -1192,6 +1208,16 @@ namespace eyemLib_Sharp
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemSplitMask(EyemImage tpImage, EyemImage tpMask, string toPath, string className);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemNamedWindow(string winName);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemImshow(string winName, EyemImage tpImage);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemWaitkey();
#endregion
#region 日志功能
......@@ -1226,7 +1252,7 @@ namespace eyemLib_Sharp
//eyemInitONNXModel("D:\\训练数据集\\Parts-11\\backup\\ec_model.onnx");
eyemInitCounter("D://pre_segmentation.onnx");
//eyemInitCounter("D://pre_segmentation.onnx");
}
public static void Free()
......@@ -1249,12 +1275,11 @@ namespace eyemLib_Sharp
#endregion
static int index = 0;
public static void eyemReadImageTool(string fileName)
{
EyemImage image;
EyemImage tpDstImg = new EyemImage();
EyemImage tpDstImg;
int flag = eyemImageRead(fileName, -1, out image);
if (flag != 0)
{
......@@ -1265,6 +1290,13 @@ namespace eyemLib_Sharp
sw.Restart();
string file = fileName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[2];
//_ = eyemBinThreshold(image, 1, 45, 255, out tpDstImg);
////eyemNamedWindow("test");
////eyemImshow("test", image);
////eyemWaitkey();
//return;
//flag = eyemInitNNDetector(".\\darknet\\cifar_resnet50.cfg", ".\\darknet\\cifar_resnet50.weights");
//if (flag == 0)
//{
......@@ -1372,9 +1404,34 @@ namespace eyemLib_Sharp
//EyemImage tpPrevImg = new EyemImage();
//flag = eyemAchvMaskImage(image, out tpDstImg, out tpPrevImg);
//sw.Restart();
// flag = eyemLibImpl(image, out tpDstImg);
//eyemAffineTransform(image, 90, new EyemOcsDXY(), out image);
////彩色图像预处理
//EyemHSVModel tpHsvModel = new EyemHSVModel();
////tpHsvModel.dpRangeL = new double[] { 35, 60, 20 }; tpHsvModel.dpRangeU = new double[] { 100, 255, 255 };
////tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
//tpHsvModel.dpRangeL = new double[] { 60, 56, 50 }; tpHsvModel.dpRangeU = new double[] { 80, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
//EyemImage tpMask;
//eyemBinThresholdC(image, tpHsvModel, out tpMask);
//EyemRect tpRoi0 = new EyemRect();
//tpRoi0.iXs = 4420; tpRoi0.iYs = 2206;
//tpRoi0.iWidth = 639;
//tpRoi0.iHeight = 1373;
//////预处理提取出PCB板
//flag = eyemAOIPreprocessingForTSAV(image, tpRoi0, out tpDstImg);
//sw.Stop();
//Console.WriteLine("时间花费:"+sw.ElapsedMilliseconds.ToString());
//Console.WriteLine("时间花费:" + sw.ElapsedMilliseconds.ToString());
flag = eyemLibImpl(image, out tpDstImg);
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
if (bitmap != null)
{
//bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
bitmap.Save("D:\\ResOut\\" + file);
}
eyemImageFree(ref image);
eyemImageFree(ref tpDstImg);
return;
//flag = eyemAffineTransform(image, 2.2965, out tpDstImg);
//sw.Stop();
//Console.WriteLine("时间花费:" + sw.ElapsedMilliseconds.ToString());
......@@ -1406,58 +1463,179 @@ namespace eyemLib_Sharp
//每运行检测一次释放一次
//eyemImageFree(ref tpDstImg);
//eyemImageFree(ref image);
//////mask可以在程序启动与关闭时加载/释放
////eyemImageFree(ref mask);
//////////mask可以在程序启动与关闭时加载/释放
//eyemImageFree(ref tpMask);
//eyemImageFree(ref tpDstImg);
//eyemImageFree(ref tpPrevImg);
//////eyemImageFree(ref tpPrevImg);
//return;
//EyemImage templ, search;
//flag = eyemImageRead("D://批量测试图像//Dst10.png", -1, out templ);
//if (flag != 0)
//{
// Console.WriteLine("读图失败!");
// return;
//}
#region 插件机AOI流程
//EyemImage search, templ, template;
////每次运行检测获取的待检测图像
////flag = eyemImageRead("D://search.png", -1, out search);
////if (flag != 0)
////{
//// Console.WriteLine("读图失败!");
//// return;
////}
//////一开始获取的模板图像,保存用来划定检测区域
////flag = eyemImageRead("D://template.png", -1, out template);
////if (flag != 0)
////{
//// Console.WriteLine("读图失败!");
//// return;
////}
//search = eyemCvtToEyemImage2((Bitmap)Image.FromFile("D://search1.bmp"));
//template = eyemCvtToEyemImage2((Bitmap)Image.FromFile("D://template1.bmp"));
////制作模板时元件位置
//List<EyemRect> tpRois = new List<EyemRect>();
//EyemRect roi1 = new EyemRect();
//roi1.iXs = 151; roi1.iYs = 273; roi1.iWidth = 330; roi1.iHeight = 119;
//EyemRect roi2 = new EyemRect();
//roi2.iXs = 119; roi2.iYs = 589; roi2.iWidth = 70; roi2.iHeight = 155;
//tpRois.Add(roi1); tpRois.Add(roi2);
////EyemImage target;
//flag = eyemImageRead("D://批量测试图像//Src10.png", -1, out search);
//flag = eyemSIFTBasedMatch(image, target, new EyemImage(), 0.6, out tpDstImg);
//return;
int iNumMatches = 1;
double dToleranceAngle = 0.0;
double dMaxOverlap = 0.0;
double dScore = 0.8;
//flag = eyemImageRead("D://算法测试图像//fiducial_input.png", -1, out search);
//if (flag != 0)
//{
// Console.WriteLine("读图失败!");
// return;
//}
EyemOcsDXY dXY = new EyemOcsDXY();
List<EyemOcsDXY> dXiesA = new List<EyemOcsDXY>() { };//测试图中的点
List<EyemOcsDXY> dXiesB = new List<EyemOcsDXY>() { };//基准图中的点
//模板匹配
//EyemTargetMatch[] tpResults = new EyemTargetMatch[15];
EyemTargetMatch[] tpResults = new EyemTargetMatch[iNumMatches];
//IntPtr ModelHandle = Marshal.AllocHGlobal(checked(Marshal.SizeOf(typeof(EyemTargetMatch)) * tpResults.Length));
var ResultHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(EyemTargetMatch)) * tpResults.Length);
//flag = eyemMakeNCCModel(templ, 256);
flag = eyemMakeNCCModel(eyemCvtToEyemImage2((Bitmap)Image.FromFile("D://批量测试图像//top.png")), 256);//614 152
if (flag != 0)
return;
flag = eyemFindNCCModel(eyemCvtToEyemImage2((Bitmap)Image.FromFile("D://批量测试图像//search.bmp")), dToleranceAngle, iNumMatches, dMaxOverlap, dScore, true, ResultHandle, out tpDstImg);
if (flag != 0)
return;
tpResults = eyemIntPtr2StructArray<EyemTargetMatch>(ResultHandle, tpResults.Length).ToArray();
eyemNamedWindow("dst");
eyemImshow("dst", tpDstImg);
eyemWaitkey();
eyemImageFree(ref tpDstImg);
dXY.dX = 614 + Image.FromFile("D://批量测试图像//top.png").Width / 2;
dXY.dY = 152 + Image.FromFile("D://批量测试图像//top.png").Height / 2;
dXiesB.Add(dXY);
//flag = eyemFindNCCModel(search, 15, tpResults.Length, 0, 0.8, ModelHandle);
dXY.dX = tpResults[0].fCenterX;
dXY.dY = tpResults[0].fCenterY;
dXiesA.Add(dXY);
//tpResults = eyemIntPtr2StructArray<EyemTargetMatch>(ModelHandle, tpResults.Length).ToArray();
////eyemCvtToBitmap(tpDstImg).Save("D:\\ResOut\\" + "x.png");
//Marshal.FreeHGlobal(ModelHandle);
////框选模板匹配位置
//EyemRect tpRoiTemplate = new EyemRect();
//tpRoiTemplate.iXs = tpRoiTemplate.iYs = 15;
//tpRoiTemplate.iWidth = 109;
//tpRoiTemplate.iHeight = 259;
//eyemCopyRegion(search, tpRoiTemplate, out templ);
//eyemNamedWindow("templ");
//eyemImshow("templ", templ);
//eyemWaitkey();
//flag = eyemMakeShapeModel(templ, 100, 10);
flag = eyemMakeNCCModel(eyemCvtToEyemImage2((Bitmap)Image.FromFile("D://批量测试图像//bot.png")), 256);//1052 1156
if (flag != 0)
return;
flag = eyemFindNCCModel(eyemCvtToEyemImage2((Bitmap)Image.FromFile("D://批量测试图像//search.bmp")), dToleranceAngle, iNumMatches, dMaxOverlap, dScore, true, ResultHandle, out tpDstImg);
if (flag != 0)
return;
tpResults = eyemIntPtr2StructArray<EyemTargetMatch>(ResultHandle, tpResults.Length).ToArray();
//eyemNamedWindow("dst");
//eyemImshow("dst", tpDstImg);
//eyemWaitkey();
//eyemImageFree(ref tpDstImg);
//dXY.dX = 1052 + Image.FromFile("D://批量测试图像//bot.png").Width / 2;
//dXY.dY = 1156 + Image.FromFile("D://批量测试图像//bot.png").Height / 2;
//dXiesB.Add(dXY);
//dXY.dX = tpResults[0].fCenterX;
//dXY.dY = tpResults[0].fCenterY;
//dXiesA.Add(dXY);
//var mtx = new EyemRigidMatrix();
//eyemFitRTMatrix(dXiesA.Count, false, eyemStructArray2IntPtr(dXiesA.ToArray()), eyemStructArray2IntPtr(dXiesB.ToArray()), ref mtx);
return;
////flag = eyemMakeShapeModel(templ, 100, 10);
////flag = eyemFindShapeModel(search, 10, 0, 90, 1, 10, 100, 0.7, 0.7);
//flag = eyemFindShapeModel(search, 10, 0, 90, 1, 10, 100, 0.7, 0.7);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
// for (int i = 0; i < tpRois.Count; i++)
// {
// using (Graphics g = Graphics.FromImage(bitmap))
// {
// g.DrawRectangle(Pens.Red, new Rectangle(tpRois[i].iXs, tpRois[i].iYs, tpRois[i].iWidth, tpRois[i].iHeight));
// }
// }
// bitmap.Save("D:\\ResOut\\" + "old.png");
//}
//for (int i = 0; i < tpResults.Length; i++)
//{
// if (tpResults[i].fMatchScore > 0)
// {
// Console.WriteLine(string.Format("目标{0},位置({1},{2}),匹配分数{3}",
// i, tpResults[i].fCenterX.ToString("F3"), tpResults[i].fCenterY.ToString("F3"), tpResults[i].fMatchScore.ToString("F3")));
// }
//}
////根据模板匹配重新确定候选框位置
//EyemRect rect = new EyemRect();
//for (int i = 0; i < tpRois.Count; i++)
//{
// int offsetX = tpRois[i].iXs - (int)(Math.Round(tpResults[0].fCenterX - templ.iWidth / 2.0)) + tpRoiTemplate.iXs;
// int offsetY = tpRois[i].iYs - (int)(Math.Round(tpResults[0].fCenterY - templ.iHeight / 2.0)) + tpRoiTemplate.iYs;
// rect.iXs = offsetX;
// rect.iYs = offsetY;
// rect.iWidth = tpRois[i].iWidth; rect.iHeight = tpRois[i].iHeight;
// tpRois[i] = rect;
//}
//Bitmap bitmap1 = new Bitmap("D://search1.bmp");
//for (int i = 0; i < tpRois.Count; i++)
//{
// using (Graphics g = Graphics.FromImage(bitmap1))
// {
// g.DrawRectangle(Pens.Red, new Rectangle(tpRois[i].iXs, tpRois[i].iYs, tpRois[i].iWidth, tpRois[i].iHeight));
// }
//}
//using (Graphics g = Graphics.FromImage(bitmap1))
//{
// g.DrawRectangle(Pens.Green, new Rectangle(tpRoiTemplate.iXs, tpRoiTemplate.iYs, tpRoiTemplate.iWidth, tpRoiTemplate.iHeight));
//}
//bitmap1.Save("D:\\ResOut\\new.png");
//sw.Stop();
//Console.WriteLine("时间花费" + sw.ElapsedMilliseconds.ToString());
//eyemImageFree(ref templ);
//eyemImageFree(ref search);
//eyemImageFree(ref template);
//Marshal.FreeHGlobal(ResultHandle);
//return;
#endregion
//return;
//EyemImage image1 = new EyemImage(); EyemImage image2 = new EyemImage(); EyemImage image3 = new EyemImage();
......@@ -1727,8 +1905,8 @@ namespace eyemLib_Sharp
int[] ipReelNum = new int[4];
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS","IP_SQUARE_PARTS","IP_DYNAMIC_PARTS","","IP_DYNAMIC_SP1","IP_DYNAMIC_SP2"
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "IP_LONG_PARTS", ipReelNum, out tpDstImg);
eyemCountObjectE(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "IP_SMALL_PARTS", ipReelNum, out tpDstImg);
//eyemCountObjectE(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + "20210825095751-1.tpl", hModelID, ipReelNum, out tpDstImg);
//算法选项
//std::string sOptions[8] = { "IP_DEFAULT_PARTS","IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS","IP_SQUARE_PARTS","","IP_DYNAMIC_SP1","IP_DYNAMIC_SP2" };
......@@ -1763,14 +1941,14 @@ namespace eyemLib_Sharp
}
sw.Stop();
Console.WriteLine(file + "--->" + "耗时:" + sw.ElapsedMilliseconds.ToString() + "ms" + ",结果:" + strReelNum);
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
if (bitmap != null)
Bitmap bitmapE = eyemCvtToBitmap(tpDstImg);
if (bitmapE != null)
{
bitmap.Save("D:\\ResOut\\" + file);
bitmapE.Save("D:\\ResOut\\" + file);
}
////计数失败
//if (flag != 0)
// File.Copy(fileName, "D:\\ResOut\\" + file, true);
//计数失败
if (flag != 0 || (ipReelNum[0] + ipReelNum[1] + ipReelNum[2] + ipReelNum[3]) == 0)
File.Copy(fileName, "D:\\ResOut\\" + file, true);
//for (int i = 0; i < ipNum; i++)
//{
......
......@@ -80,6 +80,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="EyemLib.cs" />
<Compile Include="EyemLib.DotNet.cs" />
<Compile Include="EyemLibDemo.cs" />
<Compile Include="log4cpp\ILog4CPP.cs" />
<Compile Include="log4cpp\Log4CPPBase.cs" />
......

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32602.291
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eyemLib.Control", "eyemLib.Control\eyemLib.Control.csproj", "{E46DBA02-311F-417A-9221-6F4172498595}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eyemLib.Control.Test", "eyemLib.Control.Test\eyemLib.Control.Test.csproj", "{73B3D8D8-0703-4DB8-8266-053D840BDACE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E46DBA02-311F-417A-9221-6F4172498595}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release|Any CPU.Build.0 = Release|Any CPU
{73B3D8D8-0703-4DB8-8266-053D840BDACE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73B3D8D8-0703-4DB8-8266-053D840BDACE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73B3D8D8-0703-4DB8-8266-053D840BDACE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73B3D8D8-0703-4DB8-8266-053D840BDACE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {862264CB-71CB-486C-B0FE-8E6FCDB50BB6}
EndGlobalSection
EndGlobal
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace eyemLib.Control
{
[Description("直方图控件")]
[Docking(DockingBehavior.Ask)]
[ToolboxItem(true)]
public class Histogram : UserControl
{
private IContainer components;
public Label lblX1;
public Label lblX2;
private ToolTip tltHistogram;
private Label lblHistScope;
private bool m_InitializedFlg;
private bool m_isDisposing;
private BufferedGraphicsContext m_backbufferContext;
private BufferedGraphics m_BackbufferGraphics;
private Graphics m_Graphics;
private int[,] m_Hist;
private bool m_Drawing;
private HISTOGRAMINFO[] m_HistogramChInfo;
private HISTOGRAMINFO m_HistogramInfo;
private float m_Scale;
private Rectangle m_HistRect;
private bool m_Navigate;
private bool m_MouseDownFlg;
private bool m_FirstFlg;
private Point m_StartPoint;
private Point m_EndPoint;
private bool m_ToolTip;
private int m_nColor;
private int m_X1;
private int m_X2;
private Color m_ActiveBackColor;
private Color m_NonActiveBackColor;
private int m_Padding_Top;
private int m_Padding_Right;
private int m_Padding_Bottom;
private int m_Padding_Left;
private void InitializeComponent()
{
lblHistScope = new Label();
lblX1 = new Label();
lblX2 = new Label();
SuspendLayout();
//
// lblHistScope
//
lblHistScope.BackColor = Color.Transparent;
lblHistScope.ForeColor = SystemColors.ControlText;
lblHistScope.Location = new Point(67, 42);
lblHistScope.Name = "lblHistScope";
lblHistScope.Size = new Size(120, 283);
lblHistScope.TabIndex = 0;
lblHistScope.Visible = false;
lblHistScope.Paint += new PaintEventHandler(lblHistScope_Paint);
lblHistScope.Resize += new EventHandler(lblHistScope_Resize);
//
// lblX1
//
lblX1.AutoSize = true;
lblX1.Location = new Point(72, 184);
lblX1.Name = "lblX1";
lblX1.Size = new Size(15, 15);
lblX1.TabIndex = 1;
lblX1.Visible = false;
lblX1.Text = "0";
lblX1.Click += new EventHandler(lblX1_Click);
//
// lblX2
//
lblX2.AutoSize = true;
lblX2.Location = new System.Drawing.Point(153, 184);
lblX2.Name = "lblX2";
lblX2.Size = new System.Drawing.Size(31, 15);
lblX2.TabIndex = 2;
lblX2.Visible = false;
lblX2.Text = "255";
lblX2.Click += new System.EventHandler(lblX2_Click);
//
// Histogram
//
Controls.Add(lblX2);
Controls.Add(lblX1);
Controls.Add(lblHistScope);
Name = "Histogram";
Size = new System.Drawing.Size(710, 364);
MouseDown += new System.Windows.Forms.MouseEventHandler(Histogram_MouseDown);
MouseMove += new System.Windows.Forms.MouseEventHandler(Histogram_MouseMove);
MouseUp += new System.Windows.Forms.MouseEventHandler(Histogram_MouseUp);
ResumeLayout(false);
PerformLayout();
}
public Histogram()
{
InitializeComponent();
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, false);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.Opaque, true);
m_backbufferContext = BufferedGraphicsManager.Current;
m_InitializedFlg = true;
m_Navigate = true;
m_Scale = 1f;
m_Padding_Top = 10;
m_Padding_Right = 20;
m_Padding_Bottom = 13;
m_Padding_Left = 35;
m_ActiveBackColor = Color.Yellow;
m_NonActiveBackColor = Color.Aquamarine;
lblX1.BackColor = BackColor;
lblX2.BackColor = BackColor;
RecreateBuffers();
}
protected override void Dispose(bool disposing)
{
m_isDisposing = true;
if (disposing && components != null)
components.Dispose();
base.Dispose(disposing);
}
protected override void OnPaint(PaintEventArgs e)
{
if (m_isDisposing || m_BackbufferGraphics == null)
return;
m_BackbufferGraphics.Render(e.Graphics);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
RecreateBuffers();
lblHistScope.Location = new Point(lblHistScope.Left, m_Padding_Top);
lblHistScope.Size = new Size(lblHistScope.Size.Width, Height - m_Padding_Top - m_Padding_Bottom);
DrawHistogram(m_Hist);
}
private void RecreateBuffers()
{
if (!m_InitializedFlg || m_isDisposing)
return;
m_backbufferContext.MaximumBuffer = new Size(Width + 1, Height + 1);
if (m_BackbufferGraphics != null)
m_BackbufferGraphics.Dispose();
m_BackbufferGraphics = m_backbufferContext.Allocate(CreateGraphics(), new Rectangle(0, 0, Math.Max(Width, 1), Math.Max(Height, 1)));
m_Graphics = m_BackbufferGraphics.Graphics;
m_Graphics.Clear(BackColor);
Invalidate();
}
public new float Scale
{
get => m_Scale;
set
{
m_Scale = value;
DrawHistogram(m_Hist);
}
}
public int X1
{
get => m_X1;
set
{
DrawNavigate(m_X1, m_X2);
m_X1 = value;
if (m_X1 > m_X2)
m_X1 = m_X2;
if (m_X1 < 0)
m_X1 = 0;
if (m_X1 >= m_nColor)
m_X1 = m_nColor - 1;
DrawNavigate(m_X1, m_X2);
}
}
public int X2
{
get => m_X2;
set
{
DrawNavigate(m_X1, m_X2);
m_X2 = value;
if (m_X1 > m_X2)
m_X2 = m_X1;
if (m_X2 < 0)
m_X2 = 0;
if (m_X2 >= m_nColor)
m_X2 = m_nColor - 1;
DrawNavigate(m_X1, m_X2);
}
}
public bool Navigate
{
get => m_Navigate;
set => m_Navigate = value;
}
public bool ToolTip
{
get => m_ToolTip;
set => m_ToolTip = value;
}
public int SetDrawRectTrans(
Graphics g,
float SrcWidth,
float SrcHeight,
int DstWidth,
int DstHeight,
int PaddingTop,
int PaddingRight,
int PaddingBottom,
int PaddingLeft)
{
if (InvokeRequired)
{
Invoke(new SetDrawRectTransDelegate(SetDrawRectTrans), (object)g, (object)SrcWidth, (object)SrcHeight, (object)DstWidth, (object)DstHeight, (object)PaddingTop, (object)PaddingRight, (object)PaddingBottom, (object)PaddingLeft);
return 0;
}
RectangleF rectangleF = new RectangleF((float)PaddingLeft, (float)PaddingTop, (float)(DstWidth - PaddingLeft - PaddingRight), (float)(DstHeight - PaddingTop - PaddingBottom));
if ((double)rectangleF.Width <= 0.0 || (double)rectangleF.Height <= 0.0)
return -1;
lock (g)
{
g.ResetTransform();
g.ScaleTransform(rectangleF.Width / SrcWidth, -rectangleF.Height / SrcHeight, MatrixOrder.Append);
g.TranslateTransform(rectangleF.Left - 1f, rectangleF.Bottom - 1f, MatrixOrder.Append);
}
return 0;
}
public void DrawHistogram(int[,] Hist)
{
try
{
if (InvokeRequired)
{
Invoke(new DrawHistogramIntArrDelegate(DrawHistogram), (object)Hist);
}
else
{
if (Hist == null || m_Drawing)
return;
m_Drawing = true;
m_Hist = Hist;
lblX1.Visible = lblX2.Visible = false;
lblHistScope.Visible = false;
int num1 = Hist.GetUpperBound(0) + 1;
m_nColor = Hist.GetUpperBound(1) + 1;
m_Graphics.Clear(BackColor);
m_HistRect = new Rectangle(m_Padding_Left, m_Padding_Top, Width - m_Padding_Left - m_Padding_Right, Height - m_Padding_Top - m_Padding_Bottom);
CalcHistogramInfo(m_Hist);
float num2 = m_HistogramInfo.MaxCountNonLimit != 0 ? (float)m_HistogramInfo.MaxCountNonLimit : (float)m_HistogramInfo.MaxCount;
if ((double)num2 <= 0.0)
num2 = 1f;
if (SetDrawRectTrans(m_Graphics, (float)m_nColor, num2 / m_Scale, Width, Height, m_Padding_Top, m_Padding_Right, m_Padding_Bottom, m_Padding_Left) < 0)
{
m_Drawing = false;
}
else
{
Point[] points = new Point[m_nColor * 2 + 2];
LinearGradientBrush[] linearGradientBrushArray = new LinearGradientBrush[4]
{
new LinearGradientBrush(new RectangleF(0.0f, 0.0f, (float) m_nColor, num2 / m_Scale), Color.FromArgb(100, 0, 0, 30), Color.FromArgb(80, 0, 0, (int) byte.MaxValue), LinearGradientMode.Vertical),
new LinearGradientBrush(new RectangleF(0.0f, 0.0f, (float) m_nColor, num2 / m_Scale), Color.FromArgb(100, 0, 30, 0), Color.FromArgb(80, 0, (int) byte.MaxValue, 0), LinearGradientMode.Vertical),
new LinearGradientBrush(new RectangleF(0.0f, 0.0f, (float) m_nColor, num2 / m_Scale), Color.FromArgb(100, 30, 0, 0), Color.FromArgb(80, (int) byte.MaxValue, 0, 0), LinearGradientMode.Vertical),
new LinearGradientBrush(new RectangleF(0.0f, 0.0f, (float) m_nColor, num2 / m_Scale), Color.FromArgb(100, 0, 0, 0), Color.FromArgb(80, (int) byte.MaxValue, (int) byte.MaxValue, (int) byte.MaxValue), LinearGradientMode.Vertical)
};
SolidBrush[] solidBrushArray = new SolidBrush[4]
{
new SolidBrush(Color.FromArgb(60, 0, 0, (int) byte.MaxValue)),
new SolidBrush(Color.FromArgb(60, 0, (int) byte.MaxValue, 0)),
new SolidBrush(Color.FromArgb(60, (int) byte.MaxValue, 0, 0)),
new SolidBrush(Color.FromArgb(60, 0, 0, 0))
};
Pen[] penArray = new Pen[4]
{
new Pen(Color.Blue, 0.1f),
new Pen(Color.Green, 0.1f),
new Pen(Color.Red, 0.1f),
new Pen(Color.Gray, 0.1f)
};
for (int index1 = 0; index1 < num1; ++index1)
{
for (int index2 = 0; index2 < m_nColor; ++index2)
{
points[index2 * 2].X = index2;
points[index2 * 2].Y = Hist[index1, index2];
points[index2 * 2 + 1].X = index2 + 1;
points[index2 * 2 + 1].Y = Hist[index1, index2];
}
points[m_nColor * 2].X = m_nColor;
points[m_nColor * 2].Y = 0;
points[m_nColor * 2 + 1].X = 0;
points[m_nColor * 2 + 1].Y = 0;
m_Graphics.FillPolygon((Brush)linearGradientBrushArray[index1], points);
m_Graphics.DrawPolygon(penArray[index1], points);
}
m_Graphics.ResetTransform();
Pen pen1 = new Pen(Color.FromArgb(50, 50, 50), 2f);
m_Graphics.DrawLine(pen1, new PointF((float)(m_HistRect.Left - 2), (float)m_HistRect.Bottom), new PointF((float)m_HistRect.Right, (float)m_HistRect.Bottom));
m_Graphics.DrawLine(pen1, m_HistRect.Left - 2, m_HistRect.Top, m_HistRect.Left - 2, m_HistRect.Bottom);
Pen pen2 = new Pen(Color.FromArgb(70, 50, 50, 50), 1f);
for (int index = 1; index < 5; ++index)
m_Graphics.DrawLine(pen2, m_HistRect.Left + m_HistRect.Width * index / 4, m_HistRect.Top, m_HistRect.Left + m_HistRect.Width * index / 4, m_HistRect.Bottom);
m_Graphics.DrawLine(pen2, m_HistRect.Left - 2, m_HistRect.Bottom - m_HistRect.Height, m_HistRect.Right - 2, m_HistRect.Bottom - m_HistRect.Height);
m_Graphics.DrawLine(pen2, m_HistRect.Left + m_HistRect.Width, m_HistRect.Top, m_HistRect.Left + m_HistRect.Width, m_HistRect.Bottom);
SolidBrush solidBrush1 = new SolidBrush(Color.FromArgb(10, 0, 0, 0));
m_Graphics.FillRectangle((Brush)solidBrush1, m_HistRect.Left, m_HistRect.Top, m_HistRect.Width, m_HistRect.Height / 4);
m_Graphics.FillRectangle((Brush)solidBrush1, m_HistRect.Left, m_HistRect.Top + m_HistRect.Height / 2, m_HistRect.Width, m_HistRect.Height / 4);
float emSize = 6.5f;
Font font = new Font("Arial", emSize, FontStyle.Bold);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Far;
SolidBrush solidBrush2 = new SolidBrush(Color.FromArgb(45, 45, 45));
for (int index = 0; index < 5; ++index)
m_Graphics.DrawString(((int)((double)num2 / (double)m_Scale * (double)index / 4.0)).ToString(), font, (Brush)solidBrush2, new PointF((float)(m_Padding_Left - 2), (float)(m_HistRect.Bottom - m_HistRect.Height * index / 4) - emSize / 1.5f), format);
m_Graphics.DrawString((m_nColor - 1).ToString(), font, (Brush)solidBrush2, new PointF((float)(m_HistRect.Right + 1), (float)(m_HistRect.Bottom + 1)), format);
Invalidate();
m_Drawing = false;
}
}
}
catch (Exception)
{
}
}
public void DrawHistogram(Bitmap bmp)
{
if (InvokeRequired)
{
Invoke((Delegate)new Histogram.DrawHistogramBmpDelegate(DrawHistogram), (object)bmp);
}
else
{
m_Hist = (int[,])null;
GetHistCount(bmp, ref m_Hist);
DrawHistogram(m_Hist);
}
}
public unsafe void GetHistCount(
IntPtr pSrc,
int Width,
int Height,
int Stride,
int ValidBitCount,
ref int[,] Hist)
{
if (InvokeRequired)
{
Invoke(new Histogram.GetHistCountDelegate(GetHistCount), (object)pSrc, (object)Width, (object)Height, (object)Stride, (object)ValidBitCount, (object)Hist);
}
else
{
if (pSrc == IntPtr.Zero)
return;
if (ValidBitCount == 8 || ValidBitCount == 24 || ValidBitCount == 32)
{
int length1 = ValidBitCount / 8;
int length2 = 256;
if (Hist != null)
Hist = (int[,])null;
Hist = new int[length1, length2];
byte* numPtr1 = (byte*)(void*)pSrc;
for (int index1 = 0; index1 < length1; ++index1)
{
for (int index2 = 0; index2 < Height; ++index2)
{
byte* numPtr2 = numPtr1 + (index1 + index2 * Stride);
for (int index3 = 0; index3 < Width * length1; index3 += length1)
{
int index4 = (int)numPtr2[index3];
++Hist[index1, index4];
}
}
}
}
else if (8 < ValidBitCount && ValidBitCount <= 16)
{
int length3 = 1;
int length4 = 1 << ValidBitCount;
if (Hist != null)
Hist = (int[,])null;
Hist = new int[length3, length4];
if (m_HistogramChInfo != null)
m_HistogramChInfo = (Histogram.HISTOGRAMINFO[])null;
m_HistogramChInfo = new Histogram.HISTOGRAMINFO[length3];
ushort* numPtr3 = (ushort*)(void*)pSrc;
for (int index5 = 0; index5 < length3; ++index5)
{
for (int index6 = 0; index6 < Height; ++index6)
{
ushort* numPtr4 = numPtr3 + (index5 + index6 * Stride / 2);
for (int index7 = 0; index7 < Width * length3; index7 += length3)
{
int index8 = (int)numPtr4[index7];
++Hist[index5, index8];
}
}
}
}
else if (ValidBitCount == 30)
{
int length5 = 3;
int length6 = 1024;
if (Hist != null)
Hist = (int[,])null;
Hist = new int[length5, length6];
if (m_HistogramChInfo != null)
m_HistogramChInfo = (Histogram.HISTOGRAMINFO[])null;
m_HistogramChInfo = new Histogram.HISTOGRAMINFO[length5];
uint* numPtr5 = (uint*)(void*)pSrc;
uint num1 = 1072693248;
uint num2 = 1047552;
uint num3 = 1023;
for (int index9 = 0; index9 < Height; ++index9)
{
uint* numPtr6 = numPtr5 + index9 * Width;
for (int index10 = 0; index10 < Width; ++index10)
{
int index11 = (int)numPtr6[index10] & (int)num3;
++Hist[0, index11];
int index12 = (int)((numPtr6[index10] & num2) >> 10);
++Hist[1, index12];
int index13 = (int)((numPtr6[index10] & num1) >> 20);
++Hist[2, index13];
}
}
}
else
return;
CalcHistogramInfo(Hist);
}
}
public void CalcHistogramInfo(int[,] Hist)
{
if (InvokeRequired)
{
Invoke((Delegate)new Histogram.CalcHistogramInfoDelegate(CalcHistogramInfo), (object)Hist);
}
else
{
if (Hist == null)
return;
int length1 = Hist.GetLength(0);
int length2 = Hist.GetLength(1);
if (m_HistogramChInfo != null)
m_HistogramChInfo = (Histogram.HISTOGRAMINFO[])null;
m_HistogramChInfo = new Histogram.HISTOGRAMINFO[length1];
m_HistogramInfo.MinBright = length2;
m_HistogramInfo.MaxBright = 0;
m_HistogramInfo.MaxCount = 0;
m_HistogramInfo.MaxCountBright = 0;
m_HistogramInfo.MaxCountNonLimit = 0;
m_HistogramInfo.MaxCountNonLimitBright = 0;
for (int index1 = 0; index1 < length1; ++index1)
{
for (int index2 = 0; index2 < length2; ++index2)
{
if (Hist[index1, index2] != 0)
{
m_HistogramChInfo[index1].MinBright = index2;
break;
}
}
for (int index3 = length2 - 1; index3 >= 0; --index3)
{
if (Hist[index1, index3] != 0)
{
m_HistogramChInfo[index1].MaxBright = index3;
break;
}
}
int num1 = 0;
for (int index4 = 1; index4 < length2 - 1; ++index4)
{
if (num1 < Hist[index1, index4])
{
num1 = Hist[index1, index4];
m_HistogramChInfo[index1].MaxCountNonLimit = num1;
m_HistogramChInfo[index1].MaxCountNonLimitBright = index4;
}
}
m_HistogramChInfo[index1].MaxCount = m_HistogramChInfo[index1].MaxCountNonLimit;
m_HistogramChInfo[index1].MaxCountBright = m_HistogramChInfo[index1].MaxCountNonLimitBright;
if (num1 < Hist[index1, 0])
{
num1 = Hist[index1, 0];
m_HistogramChInfo[index1].MaxCount = num1;
m_HistogramChInfo[index1].MaxCountBright = 0;
}
if (num1 < Hist[index1, length2 - 1])
{
int num2 = Hist[index1, length2 - 1];
m_HistogramChInfo[index1].MaxCount = num2;
m_HistogramChInfo[index1].MaxCountBright = length2 - 1;
}
if (m_HistogramInfo.MinBright > m_HistogramChInfo[index1].MinBright)
m_HistogramInfo.MinBright = m_HistogramChInfo[index1].MinBright;
if (m_HistogramInfo.MaxBright < m_HistogramChInfo[index1].MaxBright)
m_HistogramInfo.MaxBright = m_HistogramChInfo[index1].MaxBright;
if (m_HistogramInfo.MaxCount < m_HistogramChInfo[index1].MaxCount)
m_HistogramInfo.MaxCount = m_HistogramChInfo[index1].MaxCount;
if (m_HistogramInfo.MaxCountNonLimit < m_HistogramChInfo[index1].MaxCountNonLimit)
{
m_HistogramInfo.MaxCountNonLimit = m_HistogramChInfo[index1].MaxCountNonLimit;
m_HistogramInfo.MaxCountNonLimitBright = m_HistogramChInfo[index1].MaxCountNonLimitBright;
}
m_HistogramInfo.Average = 0.0;
m_HistogramInfo.Sigma = 0.0;
}
}
}
public void GetHistCount(Bitmap bmp, ref int[,] Hist)
{
if (InvokeRequired)
{
Invoke((Delegate)new Histogram.GetHistCountBmpDelegate(GetHistCount), (object)bmp, (object)Hist);
}
else
{
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
Monitor.Enter((object)bmp);
BitmapData bitmapdata = bmp.LockBits(rect, ImageLockMode.ReadOnly, bmp.PixelFormat);
int num = Image.GetPixelFormatSize(bmp.PixelFormat) / 8;
GetHistCount(bitmapdata.Scan0, bmp.Width, bmp.Height, bitmapdata.Stride, 8 * num, ref Hist);
bmp.UnlockBits(bitmapdata);
Monitor.Exit((object)bmp);
}
}
public unsafe void GetHistCount(
byte[] ByteArr,
int width,
int height,
int Stride,
int VaildBitCount,
ref int[,] Hist)
{
if (InvokeRequired)
{
Invoke((Delegate)new Histogram.GetHistCountArrDelegate(GetHistCount), (object)ByteArr, (object)width, (object)height, (object)Stride, (object)VaildBitCount, (object)Hist);
}
else
{
fixed (byte* pSrc = &ByteArr[0])
GetHistCount((IntPtr)(void*)pSrc, width, height, Stride, VaildBitCount, ref Hist);
}
}
public void SaveHistogramData()
{
if (InvokeRequired)
{
Invoke((Delegate)new Histogram.SaveHistogramDataDelegate(SaveHistogramData));
}
else
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "CSV file (*.csv)|*.csv";
if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
return;
SaveHistogramData(saveFileDialog.FileName);
}
}
public void SaveHistogramData(string FileName)
{
if (InvokeRequired)
{
Invoke((Delegate)new Histogram.SaveHistogramDataFileDelegate(SaveHistogramData), (object)FileName);
}
else
{
if (m_Hist == null || FileName == null)
return;
int length = m_Hist.GetLength(1);
try
{
StreamWriter streamWriter = new StreamWriter(FileName, false, Encoding.GetEncoding("shift-jis"));
if (m_Hist.GetLength(0) == 1)
{
streamWriter.WriteLine("Value, Count");
for (int index = 0; index < length; ++index)
{
streamWriter.Write(index.ToString().PadLeft(4) + ", ");
streamWriter.WriteLine(m_Hist[0, index].ToString().PadLeft(8));
}
}
else
{
streamWriter.WriteLine("Value, R-Count, G-Count, B-Count");
for (int index = 0; index < length; ++index)
{
streamWriter.Write(index.ToString().PadLeft(4) + ", ");
streamWriter.Write(m_Hist[2, index].ToString().PadLeft(8) + ", ");
streamWriter.Write(m_Hist[1, index].ToString().PadLeft(8) + ", ");
streamWriter.WriteLine(m_Hist[0, index].ToString().PadLeft(8));
}
}
streamWriter.Close();
}
catch (Exception ex)
{
int num = (int)MessageBox.Show(ex.Message);
}
}
}
public void Clear() => m_Graphics.Clear(BackColor);
private void Histogram_MouseDown(object sender, MouseEventArgs e)
{
DrawHistogram(m_Hist);
m_StartPoint.X = e.X;
m_StartPoint.Y = e.Y;
if (m_HistRect != Rectangle.Empty)
{
if (m_StartPoint.X < m_HistRect.X)
m_StartPoint.X = m_HistRect.X;
if (m_StartPoint.X > m_HistRect.X + m_HistRect.Width)
m_StartPoint.X = m_HistRect.X + m_HistRect.Width;
}
lblHistScope.Location = new Point(lblHistScope.Left, m_Padding_Top);
lblHistScope.Size = new Size(lblHistScope.Size.Width, Height - m_Padding_Top - m_Padding_Bottom);
m_EndPoint = m_StartPoint;
m_MouseDownFlg = true;
m_FirstFlg = true;
}
private void Histogram_MouseMove(object sender, MouseEventArgs e)
{
if (m_EndPoint != Point.Empty && m_MouseDownFlg && !m_FirstFlg && m_EndPoint != Point.Empty)
DrawNavigate(m_StartPoint, m_EndPoint);
if (e.Button == MouseButtons.Right && m_MouseDownFlg)
{
m_EndPoint.X = e.X;
m_EndPoint.Y = e.Y;
DrawNavigate(m_StartPoint, m_EndPoint);
m_FirstFlg = false;
}
else if (e.Button == MouseButtons.Left && m_MouseDownFlg)
{
m_EndPoint.X = e.X;
m_EndPoint.Y = e.Y;
m_StartPoint = m_EndPoint;
DrawNavigate(m_EndPoint, m_EndPoint);
m_FirstFlg = false;
}
}
private void Histogram_MouseUp(object sender, MouseEventArgs e) => m_MouseDownFlg = false;
private void DrawNavigate(Point StartPoint, Point EndPoint)
{
if (m_HistRect == Rectangle.Empty || StartPoint == Point.Empty || EndPoint == Point.Empty)
return;
int x;
int num;
if (StartPoint.X < EndPoint.X)
{
x = StartPoint.X;
num = EndPoint.X;
lblX1.BackColor = m_NonActiveBackColor;
lblX2.BackColor = m_ActiveBackColor;
}
else
{
x = EndPoint.X;
num = StartPoint.X;
lblX1.BackColor = m_ActiveBackColor;
lblX2.BackColor = m_NonActiveBackColor;
}
if (x < m_HistRect.X)
x = m_HistRect.X;
if (num > m_HistRect.X + m_HistRect.Width)
num = m_HistRect.X + m_HistRect.Width;
if (m_HistRect.Width == 0)
return;
m_X1 = (int)((double)(x - m_HistRect.X) / (double)m_HistRect.Width * (double)(m_nColor - 1) + 0.5);
m_X2 = (int)((double)(num - m_HistRect.X) / (double)m_HistRect.Width * (double)(m_nColor - 1) + 0.5);
if (m_X1 < 0)
m_X1 = 0;
if (m_X2 < 0)
m_X2 = 0;
if (m_X1 > m_nColor - 1)
m_X1 = m_nColor - 1;
if (m_X2 > m_nColor - 1)
m_X2 = m_nColor - 1;
DrawNavigate(m_X1, m_X2);
}
private void DrawNavigate(int X1, int X2)
{
if (!m_Navigate || m_HistRect == Rectangle.Empty || m_StartPoint == Point.Empty || m_EndPoint == Point.Empty || m_nColor == 1)
return;
int x = (int)((double)((float)X1 - 0.5f) / (double)(m_nColor - 1) * (double)m_HistRect.Width + (double)m_HistRect.X + 0.5);
int num = (int)((double)((float)X2 + 0.5f) / (double)(m_nColor - 1) * (double)m_HistRect.Width + (double)m_HistRect.X + 0.5);
Rectangle rectangle = new Rectangle(x, m_HistRect.Y, num - x + 1, m_HistRect.Height);
lblX1.Text = X1.ToString();
lblX2.Text = X2.ToString();
if (X1 != X2)
{
if (m_nColor != 0)
{
lblX1.Visible = m_Navigate;
lblX2.Visible = m_Navigate;
lblHistScope.Visible = m_Navigate;
lblX1.Left = x - lblX1.Width;
lblX2.Left = num;
lblHistScope.Left = lblX1.Right;
lblHistScope.Width = lblX2.Left - lblX1.Right;
}
}
else if (m_nColor != 0)
{
lblX1.BackColor = m_ActiveBackColor;
lblX1.Visible = m_Navigate;
lblX2.Visible = false;
lblHistScope.Visible = m_Navigate;
lblHistScope.Width = 2;
lblHistScope.Left = x;
lblX1.Left = x - lblX1.Width / 2;
lblX2.Left = num - lblX1.Width / 2;
}
lblX1.Refresh();
lblX2.Refresh();
}
private void lblX1_Click(object sender, EventArgs e)
{
Select();
lblX1.BackColor = m_ActiveBackColor;
lblX2.BackColor = m_NonActiveBackColor;
DrawHistogram(m_Hist);
DrawNavigate(int.Parse(lblX1.Text), int.Parse(lblX2.Text));
}
private void lblX2_Click(object sender, EventArgs e)
{
Select();
lblX1.BackColor = m_NonActiveBackColor;
lblX2.BackColor = m_ActiveBackColor;
DrawHistogram(m_Hist);
DrawNavigate(int.Parse(lblX1.Text), int.Parse(lblX2.Text));
}
private void lblHistScope_Paint(object sender, PaintEventArgs e)
{
Graphics graphics = e.Graphics;
SolidBrush solidBrush = new SolidBrush(Color.FromArgb((int)byte.MaxValue, (int)byte.MaxValue, 0, 0));
graphics.FillRectangle((Brush)solidBrush, 0, 0, lblHistScope.Width, lblHistScope.Height);
graphics.DrawRectangle(new Pen(Color.Red)
{
Width = 2f
}, new Rectangle(1, 1, lblHistScope.Width - 2, lblHistScope.Height - 2));
lblHistScope.Location = new Point(lblHistScope.Left, m_Padding_Top);
lblHistScope.Size = new Size(lblHistScope.Size.Width, Height - m_Padding_Top - m_Padding_Bottom);
}
private void lblHistScope_Resize(object sender, EventArgs e)
{
GraphicsPath path = new GraphicsPath();
lblHistScope.Region = (Region)null;
path.AddRectangle(new Rectangle(0, 0, lblHistScope.Width, lblHistScope.Height));
int num = 2;
path.AddRectangle(new Rectangle(num, num, lblHistScope.Width - num * 2, lblHistScope.Height - num * 2));
lblHistScope.Region = new Region(path);
}
public struct HISTOGRAMINFO
{
public int MinBright;
public int MaxBright;
public int MaxCount;
public int MaxCountBright;
public int MaxCountNonLimit;
public int MaxCountNonLimitBright;
public double Average;
public double Sigma;
}
private delegate int SetDrawRectTransDelegate(
Graphics g,
float SrcWidth,
float SrcHeight,
int DstWidth,
int DstHeight,
int PaddingTop,
int PaddingRight,
int PaddingBottom,
int PaddingLeft);
private delegate void DrawHistogramIntArrDelegate(int[,] Hist);
private delegate void DrawHistogramBmpDelegate(Bitmap bmp);
private delegate void GetHistCountDelegate(
IntPtr pSrc,
int Width,
int Height,
int Stride,
int ValidBitCount,
ref int[,] Hist);
private delegate void CalcHistogramInfoDelegate(int[,] Hist);
private delegate void GetHistCountBmpDelegate(Bitmap bmp, ref int[,] Hist);
private delegate void GetHistCountArrDelegate(
byte[] ByteArr,
int width,
int height,
int Stride,
int VaildBitCount,
ref int[,] Hist);
private delegate void SaveHistogramDataDelegate();
private delegate void SaveHistogramDataFileDelegate();
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("eyemLib.Control")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("eyemLib.Control")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("e46dba02-311f-417a-9221-6f4172498595")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E46DBA02-311F-417A-9221-6F4172498595}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>eyemLib.Control</RootNamespace>
<AssemblyName>eyemLib.Control</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Histogram.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Histogram.resx">
<DependentUpon>Histogram.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.32602.291
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "eyemLib", "eyemLib\eyemLib.vcxproj", "{33D5F550-C799-4B05-8E14-ACA390DF5442}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eyemLib-Sharp", "eyemLib-Sharp\eyemLib-Sharp.csproj", "{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}"
ProjectSection(ProjectDependencies) = postProject
{E46DBA02-311F-417A-9221-6F4172498595} = {E46DBA02-311F-417A-9221-6F4172498595}
{33D5F550-C799-4B05-8E14-ACA390DF5442} = {33D5F550-C799-4B05-8E14-ACA390DF5442}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eyemLib.Control", "eyemLib.Control\eyemLib.Control\eyemLib.Control.csproj", "{E46DBA02-311F-417A-9221-6F4172498595}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_V455|Any CPU = Debug_V455|Any CPU
......@@ -84,8 +87,41 @@ Global
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release|x64.Build.0 = Release|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release|x86.ActiveCfg = Release|Any CPU
{C5284403-D4FD-4D83-BBAE-7A4020F1C01F}.Release|x86.Build.0 = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug_V455|Any CPU.ActiveCfg = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug_V455|Any CPU.Build.0 = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug_V455|x64.ActiveCfg = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug_V455|x64.Build.0 = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug_V455|x86.ActiveCfg = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug_V455|x86.Build.0 = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug|x64.ActiveCfg = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug|x64.Build.0 = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug|x86.ActiveCfg = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Debug|x86.Build.0 = Debug|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release_V420Qisda|Any CPU.ActiveCfg = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release_V420Qisda|Any CPU.Build.0 = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release_V420Qisda|x64.ActiveCfg = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release_V420Qisda|x64.Build.0 = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release_V420Qisda|x86.ActiveCfg = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release_V420Qisda|x86.Build.0 = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release_V455|Any CPU.ActiveCfg = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release_V455|Any CPU.Build.0 = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release_V455|x64.ActiveCfg = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release_V455|x64.Build.0 = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release_V455|x86.ActiveCfg = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release_V455|x86.Build.0 = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release|Any CPU.Build.0 = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release|x64.ActiveCfg = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release|x64.Build.0 = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release|x86.ActiveCfg = Release|Any CPU
{E46DBA02-311F-417A-9221-6F4172498595}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {06C492F5-AFB7-4B87-B91B-86076725DE66}
EndGlobalSection
EndGlobal
#include "azONNXWrapper.h"
static void sigmoid(cv::Mat& out, int length)
{
#pragma warning( disable : 26451 )
float* pdata = (float*)(out.data);
for (int i = 0; i < length; i++)
{
pdata[i] = 1.0 / (1 + expf(-pdata[i]));
}
}
static float sigmoid_x(float x)
{
return static_cast<float>(1.f / (1.f + exp(-x)));
}
static void create_priorbox(float* priorbox, const int conv_ws[5], const int conv_hs[5], const float scales[5], const float aspect_ratios[3], const int target_size)
{
float* pb = priorbox;
for (int p = 0; p < 5; p++)
{
int conv_w = conv_ws[p];
int conv_h = conv_hs[p];
float scale = scales[p];
for (int i = 0; i < conv_h; i++)
{
for (int j = 0; j < conv_w; j++)
{
// +0.5 because priors are in center-size notation
float cx = (j + 0.5f) / conv_w;
float cy = (i + 0.5f) / conv_h;
for (int k = 0; k < 3; k++)
{
float ar = aspect_ratios[k];
ar = sqrt(ar);
float w = scale * ar / target_size;
float h = scale / ar / target_size;
// This is for backward compatability with a bug where I made everything square by accident
// cfg.backbone.use_square_anchors:
h = w;
pb[0] = cx;
pb[1] = cy;
pb[2] = w;
pb[3] = h;
pb += 4;
}
}
}
}
}
static void create_protomask(std::vector<cv::Mat>& blobs, cv::Mat& mask, int mask_h, int mask_w, int maskId)
{
#pragma warning( disable : 26451 )
int channel = blobs[2].cols;
int length = mask_h * mask_w;
float* coeff = (float*)blobs[2].data + maskId * channel;
float* pm = (float*)mask.data;
const float* pmaskmap = (float*)blobs[3].data;
for (int j = 0; j < length; j++)
{
for (int p = 0; p < channel; p++)
{
pm[j] += pmaskmap[p] * coeff[p];
}
pmaskmap += channel;
}
sigmoid(mask, length);
}
int AZONNXWrapper::init(const std::string& model_path)
{
if (!model_path.empty()) {
//加载并初始化网络
net_ = cv::dnn::readNetFromONNX(model_path);
net_.setPreferableBackend(cv::dnn::Backend::DNN_BACKEND_OPENCV);
net_.setPreferableTarget(cv::dnn::Target::DNN_TARGET_OPENCL);
try {
//加载并初始化网络
net_ = cv::dnn::readNet(model_path);
net_.setPreferableBackend(cv::dnn::Backend::DNN_BACKEND_OPENCV);
net_.setPreferableTarget(cv::dnn::Target::DNN_TARGET_CPU);
}
catch (const std::exception& e) {
printf(e.what());
return -1;
}
return 0;
}
return -1;
}
float* AZONNXWrapper::forward(cv::Mat img, cv::Scalar mean, cv::Scalar std)
void AZONNXWrapper::setInputParams(float fConfThreshold, float fNmsThreshold, int top_k)
{
this->fConfThreshold = fConfThreshold;
this->fNmsThreshold = fNmsThreshold;
this->top_k = top_k;
}
float* AZONNXWrapper::forward(cv::Mat& img, cv::Scalar& mean, cv::Scalar& std)
{
CV_Assert(!img.empty());
//图像预处理,仅支持三通道
......@@ -42,62 +130,290 @@ float* AZONNXWrapper::forward(cv::Mat img, cv::Scalar mean, cv::Scalar std)
return predictions;
}
void AZONNXWrapper::forward(cv::Mat& img, cv::Mat& labels, cv::Mat& stats, cv::Mat& drawResult, cv::Scalar& mean, cv::Scalar& std)
{
#pragma warning( disable : 26451 )
CV_Assert(!img.empty());
//图像预处理,仅支持单通道
cv::Mat input;
int incn = img.channels();
if (incn != 3) {
cv::cvtColor(img, input, cv::COLOR_GRAY2BGR);
}
else {
img.copyTo(input);
}
//
cv::Mat transpMask;
img.copyTo(transpMask);
//图像尺寸
const int X = input.cols, Y = input.rows;
//交换通道
cv::cvtColor(input, input, cv::COLOR_BGR2RGB);
//图像预处理
input.convertTo(input, CV_32F, 1.0);
cv::subtract(input, mean, input);
cv::divide(input, std, input);
//设定输出
cv::Mat blob = cv::dnn::blobFromImage(input, 1.0, cv::Size(550, 550));
net_.setInput(blob);
//推理
std::vector<cv::Mat> blobs;
net_.forward(blobs, net_.getUnconnectedOutLayersNames());
AZONNXWrapper::AZONNXWrapper() {
///<获取结果...
unsigned int priors = 0;
for (int p = 0; p < 5; p++) {
priors += conv_ws[p] * conv_hs[p] * 3;
}
priorbox = new float[4 * priors];
create_priorbox(priorbox, this->conv_ws, this->conv_hs, this->scales, this->aspect_ratios, this->targetSize);
}
std::vector<int> classIds;
std::vector<float> confidences;
std::vector<cv::Rect> boxes;
std::vector<int> maskIds;
const int num_classes = blobs[1].cols;
for (int i = 0; i < priors; i++)
{
cv::Mat scores = blobs[1].row(i).colRange(1, num_classes);
AZONNXWrapper::~AZONNXWrapper()
{
delete[] predictions;
predictions = NULL;
}
double conf;
cv::Point classIdPoint;
minMaxLoc(scores, NULL, &conf, NULL, &classIdPoint);
if (conf > this->fConfThreshold)
{
const float* loc = (float*)blobs[0].data + i * 4;
const float* pb = this->priorbox + i * 4;
float pb_cx = pb[0];
float pb_cy = pb[1];
float pb_w = pb[2];
float pb_h = pb[3];
float bbox_cx = var[0] * loc[0] * pb_w + pb_cx;
float bbox_cy = var[1] * loc[1] * pb_h + pb_cy;
float bbox_w = (float)(exp(var[2] * loc[2]) * pb_w);
float bbox_h = (float)(exp(var[3] * loc[3]) * pb_h);
float obj_x1 = bbox_cx - bbox_w * 0.5f;
float obj_y1 = bbox_cy - bbox_h * 0.5f;
float obj_x2 = bbox_cx + bbox_w * 0.5f;
float obj_y2 = bbox_cy + bbox_h * 0.5f;
// clip
obj_x1 = MAX(MIN(obj_x1 * X, (float)(X - 1)), 0.f);
obj_y1 = MAX(MIN(obj_y1 * Y, (float)(Y - 1)), 0.f);
obj_x2 = MAX(MIN(obj_x2 * X, (float)(X - 1)), 0.f);
obj_y2 = MAX(MIN(obj_y2 * Y, (float)(Y - 1)), 0.f);
classIds.push_back(classIdPoint.x);
confidences.push_back(conf);
boxes.push_back(cv::Rect((int)obj_x1, (int)obj_y1, (int)(obj_x2 - obj_x1 + 1), (int)(obj_y2 - obj_y1 + 1)));
maskIds.push_back(i);
}
}
cv::Mat cc;
transpMask.copyTo(cc);
//非极大值抑制
std::vector<int> indices;
cv::dnn::NMSBoxes(boxes, confidences, fConfThreshold, fNmsThreshold, indices, 1.f, top_k);
//输出结果
labels = cv::Mat(Y, X, CV_32S, cv::Scalar(-1)), stats = cv::Mat(indices.size(), 5, CV_32FC1, cv::Scalar(0));
for (int i = 0; i < indices.size(); ++i)
{
int idx = indices[i];
cv::Rect box = boxes[idx];
int xmax = box.x + box.width;
int ymax = box.y + box.height;
cv::rectangle(cc, cv::Point(box.x, box.y), cv::Point(xmax, ymax), cv::Scalar(0, 0, 255, 255), 1);
int AZONNXWrapperEx::init(const std::string& model_path)
{
if (!model_path.empty()) {
//加载并初始化网络
net_ = cv::dnn::readNetFromONNX(model_path);
net_.setPreferableBackend(cv::dnn::Backend::DNN_BACKEND_OPENCV);
net_.setPreferableTarget(cv::dnn::Target::DNN_TARGET_CPU);
return 0;
int label = classIds[idx];
//获取实例掩膜
cv::Mat mask(this->mask_h, this->mask_w, CV_32FC1, cv::Scalar(0.f));
create_protomask(blobs, mask, this->mask_h, this->mask_w, maskIds[idx]);
//位置信息
stats.ptr<float_t>(i)[0] = box.x; stats.ptr<float_t>(i)[1] = box.y;
stats.ptr<float_t>(i)[2] = xmax; stats.ptr<float_t>(i)[3] = ymax; stats.ptr<float_t>(i)[4] = confidences[idx];
//恢复真实尺度
cv::resize(mask, mask, cv::Size(X, Y));
cv::Mat mask0(Y, X, CV_8UC1, cv::Scalar(0));
cv::rectangle(mask0, cv::Point(box.x, box.y), cv::Point(xmax, ymax), cv::Scalar(255), -1);
cv::parallel_for_(cv::Range(0, Y), [&](const cv::Range range)->void {
for (int y = range.start; y < range.end; y++)
{
uchar* ptrmask = mask0.ptr<uchar>(y);
for (int x = 0; x < X; x++)
{
if (mask.ptr<float>(y)[x] > fConfThreshold && ptrmask[x] > 0) {
labels.ptr<int32_t>(y)[x] = label;
}
}
}
});
//标签与置信度
char text[256];
sprintf(text, "%s: %.2f", class_namesd[classIds[idx] + 1].c_str(), confidences[idx]);
int baseLine;
cv::Size labelSize = cv::getTextSize(text, cv::FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
int ymin = MAX(box.y, labelSize.height);
cv::rectangle(cc, cv::Point(box.x, box.y - int(1.5 * labelSize.height) - 1), cv::Point(box.x + int(1.5 * labelSize.width), box.y - 1), cv::Scalar(0, 255, 255), cv::FILLED);
cv::putText(cc, text, cv::Point(box.x, ymin - 2), cv::FONT_HERSHEY_SIMPLEX, 0.75, cv::Scalar(0, 0, 0, 255), 2);
}
return -1;
//绘制mask
cv::parallel_for_(cv::Range(0, Y), [&](const cv::Range range)->void {
for (int y = range.start; y < range.end; y++)
{
for (int x = 0; x < X; x++)
{
int label = labels.ptr<int32_t>(y)[x];
if (label != -1) {
transpMask.ptr<cv::Vec3b>(y)[x] = cv::Vec3b(colors[label][0], colors[label][1], colors[label][2]);
}
}
}
});
cv::addWeighted(cc, 0.7, transpMask, 0.3, 0, cc);
//
cc.copyTo(drawResult);
//释放资源
delete[] priorbox;
priorbox = NULL;
}
cv::Mat AZONNXWrapperEx::forward(cv::Mat& img)
{
void AZONNXWrapper::forward(cv::Mat& img) {
#pragma warning( disable : 26451 )
CV_Assert(!img.empty());
//图像预处理,仅支持单通道
cv::Mat input;
int incn = img.channels();
if (incn > 1) {
cv::cvtColor(img, input, cv::COLOR_BGR2GRAY);
if (incn != 3) {
cv::cvtColor(img, input, cv::COLOR_GRAY2BGR);
}
else {
img.copyTo(input);
}
//转float类型
input.convertTo(input, CV_32F, 1 / 255.);
//设定输出
cv::Mat blob = cv::dnn::blobFromImage(input);
const int targetSize = 640;
cv::resize(input, input, cv::Size(targetSize, targetSize));
cv::Mat blob;
cv::dnn::blobFromImage(input, blob, 1.0 / 255., cv::Size(targetSize, targetSize), cv::Scalar(114, 114, 114), true);
net_.setInput(blob);
auto x = net_.getUnconnectedOutLayersNames();
//推理
cv::Mat predicts = net_.forward();
std::vector<cv::Mat> preds;
net_.forward(preds, net_.getUnconnectedOutLayersNames());
//获取结果
std::vector<cv::Mat> blobs;
cv::dnn::imagesFromBlob(predicts, blobs);
cv::split(blobs[0], blobs);
//显示
cv::Mat mask = blobs[1] > 0;
return mask;
std::vector<int> classIds;
std::vector<float> confidences;
std::vector<cv::Rect> boxes;
float ratioY = (float)img.rows / targetSize;
float ratioX = (float)img.cols / targetSize;
const int nc = 1;
const float netStride[4] = { 8, 16.0,32,64 };
//for (int stride = 0; stride < preds.size(); stride++)
//{
// float* pdata = (float*)preds[stride].data;
// int T = (int)(targetSize / netStride[stride]);
// for (int anchor = 0; anchor < 3; anchor++)
// {
// const float anchor_w = netAnchors[stride][anchor * 2];
// const float anchor_h = netAnchors[stride][anchor * 2 + 1];
// for (int h = 0; h < T; h++)
// {
// for (int w = 0; w < T; w++)
// {
// float box_score = sigmoid_x(pdata[4]); ;//获取每一行的box框中含有某个物体的概率
// if (box_score >= fConfThreshold) {
// cv::Mat scores(1, nc, CV_32FC1, pdata + 5);
// cv::Point classIdPoint;
// double max_class_socre;
// minMaxLoc(scores, 0, &max_class_socre, 0, &classIdPoint);
// max_class_socre = sigmoid_x(max_class_socre);
// if (max_class_socre >= fConfThreshold) {
// float x = (sigmoid_x(pdata[0]) * 2.f - 0.5f + w) * netStride[stride]; //x
// float y = (sigmoid_x(pdata[1]) * 2.f - 0.5f + h) * netStride[stride]; //y
// float w = powf(sigmoid_x(pdata[2]) * 2.f, 2.f) * anchor_w; //w
// float h = powf(sigmoid_x(pdata[3]) * 2.f, 2.f) * anchor_h; //h
// int left = (int)(x - 0.5 * w) * ratioX + 0.5;
// int top = (int)(y - 0.5 * h) * ratioY + 0.5;
// classIds.push_back(classIdPoint.x);
// confidences.push_back(max_class_socre * box_score);
// boxes.push_back(cv::Rect(left, top, int(w * ratioX), int(h * ratioY)));
// }
// }
// pdata += (nc + 1);
// }
// }
// }
//}
auto layerNames = net_.getUnconnectedOutLayersNames();
//float ratioY = (float)input.rows / targetSize;
//float ratioX = (float)input.cols / targetSize;
for (int stride = 0; stride < 3; stride++)
{
float* pdata = (float*)preds[stride].data;
int gridX = (int)(targetSize / netStride[stride]);
int gridY = (int)(targetSize / netStride[stride]);
for (int anchor = 0; anchor < 3; anchor++) {
const float anchor_w = netAnchors[stride][anchor * 2];
const float anchor_h = netAnchors[stride][anchor * 2 + 1];
for (int i = 0; i < gridY; i++) {
for (int j = 0; j < gridX; j++) {
float box_score = sigmoid_x(pdata[4]); ;//获取每一行的box框中含有某个物体的概率
if (box_score >= fConfThreshold) {
cv::Mat scores(1, nc, CV_32FC1, pdata + 5);
cv::Point classIdPoint;
double max_class_socre;
minMaxLoc(scores, 0, &max_class_socre, 0, &classIdPoint);
max_class_socre = sigmoid_x(max_class_socre);
if (max_class_socre >= fConfThreshold) {
float x = (sigmoid_x(pdata[0]) * 2.f - 0.5f + j) * netStride[stride]; //x
float y = (sigmoid_x(pdata[1]) * 2.f - 0.5f + i) * netStride[stride]; //y
float w = powf(sigmoid_x(pdata[2]) * 2.f, 2.f) * anchor_w; //w
float h = powf(sigmoid_x(pdata[3]) * 2.f, 2.f) * anchor_h; //h
int left = (int)(x - 0.5 * w) * ratioX + 0.5;
int top = (int)(y - 0.5 * h) * ratioY + 0.5;
classIds.push_back(classIdPoint.x);
confidences.push_back(max_class_socre * box_score);
boxes.push_back(cv::Rect(left, top, int(w * ratioX), int(h * ratioY)));
}
}
pdata += 6;
}
}
}
}
//执行非最大抑制以消除具有较低置信度的冗余重叠框(NMS)
std::vector<int> indices;
cv::dnn::NMSBoxes(boxes, confidences, fConfThreshold, fNmsThreshold, indices);
for (int i = 0; i < indices.size(); ++i)
{
int idx = indices[i];
cv::Rect box = boxes[idx];
int xmax = box.x + box.width;
int ymax = box.y + box.height;
cv::rectangle(img, cv::Point(box.x, box.y), cv::Point(xmax, ymax), cv::Scalar(0, 0, 255, 255), 1);
}
return;
}
AZONNXWrapperEx::AZONNXWrapperEx() {
AZONNXWrapper::AZONNXWrapper() {
}
AZONNXWrapperEx::~AZONNXWrapperEx()
{
AZONNXWrapper::~AZONNXWrapper() {
delete[] predictions;
predictions = NULL;
}
\ No newline at end of file
......@@ -8,28 +8,131 @@
#include "opencv2/dnn.hpp"
#include "opencv2/imgproc.hpp"
class AZONNXWrapper
{
public:
AZONNXWrapper();
~AZONNXWrapper();
int init(const std::string& model_path);
float* forward(cv::Mat img, cv::Scalar mean, cv::Scalar std);
float* forward(cv::Mat& img, cv::Scalar& mean, cv::Scalar& std); //ResNet18提取特征[1,512]
void forward(cv::Mat& img, cv::Mat& labels, cv::Mat& stats, cv::Mat& drawResult, cv::Scalar& mean, cv::Scalar& std); //Yolact实例分割
void forward(cv::Mat& img); //YOLOV7
void setInputParams(float, float, int);
private:
int targetSize = 550;
float fConfThreshold = 0.5; float fNmsThreshold = 0.5; int top_k = 200;
float* predictions = new float[512];
cv::dnn::Net net_;
};
class AZONNXWrapperEx
{
public:
AZONNXWrapperEx();
~AZONNXWrapperEx();
int init(const std::string& model_path);
cv::Mat forward(cv::Mat& img);
private:
cv::dnn::Net net_;
const unsigned char colors[81][3] = {
{0, 255, 0},
{226, 255, 0},
{0, 94, 255},
{0, 37, 255},
{0, 255, 94},
{255, 226, 0},
{0, 18, 255},
{255, 151, 0},
{170, 0, 255},
{0, 255, 56},
{255, 0, 75},
{0, 75, 255},
{0, 255, 169},
{255, 0, 207},
{75, 255, 0},
{207, 0, 255},
{37, 0, 255},
{0, 207, 255},
{94, 0, 255},
{0, 255, 113},
{255, 18, 0},
{255, 0, 56},
{18, 0, 255},
{0, 255, 226},
{170, 255, 0},
{255, 0, 245},
{151, 255, 0},
{132, 255, 0},
{75, 0, 255},
{151, 0, 255},
{0, 151, 255},
{132, 0, 255},
{0, 255, 245},
{255, 132, 0},
{226, 0, 255},
{255, 37, 0},
{207, 255, 0},
{0, 255, 207},
{94, 255, 0},
{0, 226, 255},
{56, 255, 0},
{255, 94, 0},
{255, 113, 0},
{0, 132, 255},
{255, 0, 132},
{255, 170, 0},
{255, 0, 188},
{113, 255, 0},
{245, 0, 255},
{113, 0, 255},
{255, 188, 0},
{0, 113, 255},
{255, 0, 0},
{0, 56, 255},
{255, 0, 113},
{0, 255, 188},
{255, 0, 94},
{255, 0, 18},
{18, 255, 0},
{0, 255, 132},
{0, 188, 255},
{0, 245, 255},
{0, 169, 255},
{37, 255, 0},
{255, 0, 151},
{188, 0, 255},
{0, 255, 37},
{0, 255, 0},
{255, 0, 170},
{255, 0, 37},
{255, 75, 0},
{0, 0, 255},
{255, 207, 0},
{255, 0, 226},
{255, 245, 0},
{188, 255, 0},
{0, 255, 18},
{0, 255, 75},
{0, 255, 151},
{255, 56, 0},
{245, 255, 0}
};
std::vector<std::string> class_namesd = { "background",
"barcode", "bicycle", "car", "motorcycle", "airplane", "bus",
"train", "truck", "boat", "traffic light", "fire hydrant",
"stop sign", "parking meter", "bench", "bird", "cat", "dog",
"horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe",
"backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee",
"skis", "snowboard", "sports ball", "kite", "baseball bat",
"baseball glove", "skateboard", "surfboard", "tennis racket",
"bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl",
"banana", "apple", "sandwich", "orange", "broccoli", "carrot",
"hot dog", "pizza", "donut", "cake", "chair", "couch",
"potted plant", "bed", "dining table", "toilet", "tv", "laptop",
"mouse", "remote", "keyboard", "cell phone", "microwave", "oven",
"toaster", "sink", "refrigerator", "book", "clock", "vase",
"scissors", "teddy bear", "hair drier", "toothbrush"
};
protected:
const int conv_ws[5] = { 69, 35, 18, 9, 5 };
const int conv_hs[5] = { 69, 35, 18, 9, 5 };
const float aspect_ratios[3] = { 1.f, 0.5f, 2.f };
const float scales[5] = { 24.f, 48.f, 96.f, 192.f, 384.f };
const float var[4] = { 0.1f, 0.1f, 0.2f, 0.2f };
const int mask_h = 138;
const int mask_w = 138;
const float netAnchors[3][6] = { {12, 16, 19, 36, 40, 28},{36, 75, 76, 55, 72, 146},{142, 110, 192, 243, 459, 401} };//YOLOV7-P5
float* priorbox = NULL;
};
#endif/* __AZONNXWRAPPER_H */
......@@ -324,7 +324,7 @@ static int Mean(int hist[256])
double tot = 0, sum = 0;
for (int i = 0; i < 256; i++) {
tot += hist[i];
sum += ((double)i*hist[i]);
sum += ((double)i * hist[i]);
}
threshold = (int)floor(sum / tot);
return threshold;
......@@ -417,7 +417,7 @@ static int Otsu(int hist[])
// The float casting here is to avoid compiler warning about loss of precision and
// will prevent overflow in the case of large saturated images
denom = (double)(N1)* (N - N1); // Maximum value of denom is (N^2)/4 = approx. 3E10
denom = (double)(N1) * (N - N1); // Maximum value of denom is (N^2)/4 = approx. 3E10
if (denom != 0) {
// Float here is to avoid loss of precision when dividing
......@@ -435,7 +435,7 @@ static int Otsu(int hist[])
return kStar;
}
static double partialSum(int *y, int j)
static double partialSum(int* y, int j)
{
double x = 0;
for (int i = 0; i <= j; i++)
......@@ -611,7 +611,7 @@ static int RenyiEntropy(int hist[])
ent_obj += (norm_histo[ih] * norm_histo[ih]) / (P2[it] * P2[it]);
/* Total entropy */
tot_ent = term *((ent_back * ent_obj) > 0.0 ? log(ent_back * ent_obj) : 0.0);
tot_ent = term * ((ent_back * ent_obj) > 0.0 ? log(ent_back * ent_obj) : 0.0);
if (tot_ent > max_ent) {
max_ent = tot_ent;
......@@ -931,7 +931,7 @@ static double getThreshVal_Otsu_8u(const cv::Mat& _src)
#endif
for (i = 0; i < size.height; i++)
{
const uchar* src = _src.ptr() + step*i;
const uchar* src = _src.ptr() + step * i;
j = 0;
#if CV_ENABLE_UNROLLED
for (; j <= size.width - 4; j += 4)
......@@ -946,13 +946,13 @@ static double getThreshVal_Otsu_8u(const cv::Mat& _src)
h[src[j]]++;
}
double mu = 0, scale = 1. / (size.width*size.height);
double mu = 0, scale = 1. / (size.width * size.height);
for (i = 0; i < N; i++)
{
#if CV_ENABLE_UNROLLED
h[i] += h_unrolled[0][i] + h_unrolled[1][i] + h_unrolled[2][i];
#endif
mu += i*(double)h[i];
mu += i * (double)h[i];
}
mu *= scale;
......@@ -971,9 +971,9 @@ static double getThreshVal_Otsu_8u(const cv::Mat& _src)
if (std::min(q1, q2) < FLT_EPSILON || std::max(q1, q2) > 1. - FLT_EPSILON)
continue;
mu1 = (mu1 + i*p_i) / q1;
mu2 = (mu - q1*mu1) / q2;
sigma = q1*q2*(mu1 - mu2)*(mu1 - mu2);
mu1 = (mu1 + i * p_i) / q1;
mu2 = (mu - q1 * mu1) / q2;
sigma = q1 * q2 * (mu1 - mu2) * (mu1 - mu2);
if (sigma > max_sigma)
{
max_sigma = sigma;
......@@ -984,35 +984,44 @@ static double getThreshVal_Otsu_8u(const cv::Mat& _src)
return max_val;
}
int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double dMaxVal, EyemImage *tpDstImg)
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();
if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST;
}
cv::Mat binary;
//仅仅适用灰度图
if (image.channels() > 1) {
cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
}
cv::Mat dst;
//执行二值化操作
cv::threshold(image, binary, dThresh, dMaxVal, iLightDark);
tpDstImg->iWidth = binary.cols; tpDstImg->iHeight = binary.rows; tpDstImg->iDepth = binary.depth(); tpDstImg->iChannels = binary.channels();
cv::threshold(image, dst, dThresh, dMaxVal, iLightDark);
//拷贝数据
tpDstImg->iWidth = dst.cols; tpDstImg->iHeight = dst.rows; tpDstImg->iDepth = dst.depth(); tpDstImg->iChannels = dst.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
int _Size = tpDstImg->iWidth * tpDstImg->iHeight * tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
tpDstImg->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
//拷贝数据
memcpy(tpDstImg->vpImage, binary.data, _Size);
memcpy(tpDstImg->vpImage, dst.data, _Size);
return FUNC_OK;
}
int eyemBinNiBlack(EyemImage tpSrcImg, int iType, int iWinSize, double dK, int binMethod, double dR, EyemImage *tpDstImg)
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();
if (src.empty()) {
return FUNC_IMAGE_NOT_EXIST;
}
//仅仅适用灰度图
if (src.channels() > 1) {
cv::cvtColor(src, src, cv::COLOR_BGR2GRAY);
}
CV_Assert(iWinSize % 2 == 1 && iWinSize > 1);
if (binMethod == BINARIZATION_SAUVOLA) {
......@@ -1080,9 +1089,9 @@ int eyemBinNiBlack(EyemImage tpSrcImg, int iType, int iWinSize, double dK, int b
//输出图像
tpDstImg->iWidth = dst.cols; tpDstImg->iHeight = dst.rows; tpDstImg->iDepth = dst.depth(); tpDstImg->iChannels = dst.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
int _Size = tpDstImg->iWidth * tpDstImg->iHeight * tpDstImg->iChannels * sizeof(uint8_t);
//分配内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
tpDstImg->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
......@@ -1091,13 +1100,17 @@ int eyemBinNiBlack(EyemImage tpSrcImg, int iType, int iWinSize, double dK, int b
return FUNC_OK;
}
int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpPreImg, double dOffset, int iType, EyemImage *tpDstImg)
int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpPreImg, double dOffset, int iType, EyemImage* tpDstImg)
{
CV_Assert(MAKETYPE(tpSrcImg.iDepth, tpSrcImg.iChannels) == MAKETYPE(tpPreImg.iDepth, tpPreImg.iChannels));
cv::Mat image = cv::Mat(tpSrcImg.iHeight, tpSrcImg.iWidth, MAKETYPE(tpSrcImg.iDepth, tpSrcImg.iChannels), tpSrcImg.vpImage).clone();
if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST;
}
//仅仅适用灰度图
if (image.channels() > 1) {
cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
}
cv::Mat imagePre, variance;
cv::Mat thresh;
{
......@@ -1121,7 +1134,7 @@ int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpPreImg, double dOffset,
}
}
cv::Mat binary, showMat;
cv::compare(variance, cv::Mat::ones(imagePre.size(), imagePre.type())*dOffset, binary, cv::CMP_GT);
cv::compare(variance, cv::Mat::ones(imagePre.size(), imagePre.type()) * dOffset, binary, cv::CMP_GT);
//输出结果图像
if (NULL != tpDstImg->vpImage) {
tpDstImg->iWidth = tpDstImg->iHeight = tpDstImg->iDepth = tpDstImg->iChannels = 0;
......@@ -1131,9 +1144,9 @@ int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpPreImg, double dOffset,
}
tpDstImg->iWidth = binary.cols; tpDstImg->iHeight = binary.rows; tpDstImg->iDepth = binary.depth(); tpDstImg->iChannels = binary.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
int _Size = tpDstImg->iWidth * tpDstImg->iHeight * tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
tpDstImg->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
......@@ -1142,13 +1155,17 @@ int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpPreImg, double dOffset,
return FUNC_OK;
}
int eyemBinAutoThreshold(EyemImage tpImage, double dSigma, int iLightDark, int binMethod, EyemImage *tpDstImg)
int eyemBinAutoThreshold(EyemImage tpImage, double dSigma, int iLightDark, int binMethod, EyemImage* tpDstImg)
{
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST;
}
int(*calc_threshold_param) (int *) = 0;
//仅仅适用灰度图
if (image.channels() > 1) {
cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
}
int(*calc_threshold_param) (int*) = 0;
int threshold = 0;
switch (binMethod)
......@@ -1174,6 +1191,21 @@ int eyemBinAutoThreshold(EyemImage tpImage, double dSigma, int iLightDark, int b
case OTSU:
calc_threshold_param = Otsu;
break;
case PERCENTILE:
calc_threshold_param = Percentile;
break;
case RENYIENTROPY:
calc_threshold_param = RenyiEntropy;
break;
case SHANBHAG:
calc_threshold_param = Shanbhag;
break;
case TRIANGLE:
calc_threshold_param = Triangle;
break;
case YEN:
calc_threshold_param = Yen;
break;
default:
calc_threshold_param = Otsu;
break;
......@@ -1185,14 +1217,14 @@ int eyemBinAutoThreshold(EyemImage tpImage, double dSigma, int iLightDark, int b
for (int Y = 0; Y < 256; Y++) hist[Y] = 0;
for (int Y = 0; Y < image.rows; Y++)
{
uchar *uPtr = image.data + Y * image.cols;
uchar* uPtr = image.ptr<uchar>(Y);
for (int X = 0; X < image.cols; X++, uPtr++) hist[*uPtr]++;
}
threshold = calc_threshold_param(hist);
cv::Mat binary;
cv::threshold(image, binary, threshold, 255, iLightDark);
cv::Mat dst;
cv::threshold(image, dst, threshold, 255, iLightDark);
//输出结果图像
if (NULL != tpDstImg->vpImage) {
tpDstImg->iWidth = tpDstImg->iHeight = tpDstImg->iDepth = tpDstImg->iChannels = 0;
......@@ -1200,23 +1232,22 @@ int eyemBinAutoThreshold(EyemImage tpImage, double dSigma, int iLightDark, int b
free(tpDstImg->vpImage);
tpDstImg->vpImage = NULL;
}
tpDstImg->iWidth = binary.cols; tpDstImg->iHeight = binary.rows; tpDstImg->iDepth = binary.depth(); tpDstImg->iChannels = binary.channels();
tpDstImg->iWidth = dst.cols; tpDstImg->iHeight = dst.rows; tpDstImg->iDepth = dst.depth(); tpDstImg->iChannels = dst.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
int _Size = tpDstImg->iWidth * tpDstImg->iHeight * tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
tpDstImg->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
//拷贝数据
memcpy(tpDstImg->vpImage, binary.data, _Size);
memcpy(tpDstImg->vpImage, dst.data, _Size);
return FUNC_OK;
}
int eyemBinThresholdC(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpDstImg)
int eyemBinThresholdC(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage* tpDstImg)
{
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty())
return FUNC_IMAGE_NOT_EXIST;
//图像尺寸
......@@ -1255,9 +1286,9 @@ int eyemBinThresholdC(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpD
}
tpDstImg->iWidth = maskj.cols; tpDstImg->iHeight = maskj.rows; tpDstImg->iDepth = maskj.depth(); tpDstImg->iChannels = maskj.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
int _Size = tpDstImg->iWidth * tpDstImg->iHeight * tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
tpDstImg->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
......@@ -1266,28 +1297,28 @@ int eyemBinThresholdC(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpD
return FUNC_OK;
}
int eyemBinDilation(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg)
int eyemBinDilation(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage* tpDstImg)
{
return FUNC_OK;
}
int eyemBinErosion(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg)
int eyemBinErosion(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage* tpDstImg)
{
return FUNC_OK;
}
int eyemBinOpening(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg)
int eyemBinOpening(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage* tpDstImg)
{
return FUNC_OK;
}
int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg)
int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage* tpDstImg)
{
return FUNC_OK;
}
int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, EyemBinBlob **tpResult, int *ipNum, EyemImage *tpDstImg)
int eyemBinBlob(EyemImage tpImage, IntPtr* hObject, EyemBlobParams tpParams, EyemBinBlob** tpResult, int* ipNum, EyemImage* tpDstImg)
{
CV_Assert(tpImage.vpImage != NULL);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
......@@ -1318,7 +1349,7 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye
for (int i = 0; i < nccomps; i++) {
colors[i] = 255;
double dArea = stats.ptr<int>(i)[cv::CC_STAT_AREA];
if (!(dArea >= tpParams.minArea&&dArea <= tpParams.maxArea)) {
if (!(dArea >= tpParams.minArea && dArea <= tpParams.maxArea)) {
colors[i] = 0;
}
}
......@@ -1329,7 +1360,7 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye
//根据轮廓属性过滤
std::vector<std::vector<cv::Point>> contours;
cv::findContours(image, contours, cv::RETR_LIST, cv::CHAIN_APPROX_NONE);
for (auto&contour : contours)
for (auto& contour : contours)
{
int label = labels.at<int>(contour[0]);
//计算轮廓矩
......@@ -1415,7 +1446,7 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye
//过滤
cv::parallel_for_(cv::Range(0, Y), [&](const cv::Range& range)->void {
for (int y = range.start; y < range.end; y++) {
uint8_t *ptrRow = image.ptr<uint8_t>(y);
uint8_t* ptrRow = image.ptr<uint8_t>(y);
for (int x = 0; x < X; x++) {
int label = labels.ptr<int>(y)[x];
CV_Assert(0 <= label && label <= nccomps);
......@@ -1425,10 +1456,10 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye
}
}
}
});
});
EyemBinBlob blob; int idx = 0;
std::vector<EyemBinBlob> * tpResults = new std::vector<EyemBinBlob>();
std::vector<EyemBinBlob>* tpResults = new std::vector<EyemBinBlob>();
for (int i = 1; i < nccomps; i++) {
if (colors[i]) {
std::string label = "";
......@@ -1446,10 +1477,10 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye
double x1, y1, x2, y2;
double lengthLine = MAX(stats.ptr<int>(i)[cv::CC_STAT_WIDTH], stats.ptr<int>(i)[cv::CC_STAT_HEIGHT]) / 2.;
x1 = centroids.ptr<double>(i)[0] - lengthLine*cos(mOrientation.ptr<float>(i)[0]);
y1 = centroids.ptr<double>(i)[1] - lengthLine*sin(mOrientation.ptr<float>(i)[0]);
x2 = centroids.ptr<double>(i)[0] + lengthLine*cos(mOrientation.ptr<float>(i)[0]);
y2 = centroids.ptr<double>(i)[1] + lengthLine*sin(mOrientation.ptr<float>(i)[0]);
x1 = centroids.ptr<double>(i)[0] - lengthLine * cos(mOrientation.ptr<float>(i)[0]);
y1 = centroids.ptr<double>(i)[1] - lengthLine * sin(mOrientation.ptr<float>(i)[0]);
x2 = centroids.ptr<double>(i)[0] + lengthLine * cos(mOrientation.ptr<float>(i)[0]);
y2 = centroids.ptr<double>(i)[1] + lengthLine * sin(mOrientation.ptr<float>(i)[0]);
cv::line(showMat, cv::Point(int(x1), int(y1)), cv::Point(int(x2), int(y2)), cv::Scalar(0, 255, 0));
blob.iXs = stats.ptr<int>(i)[cv::CC_STAT_LEFT];
blob.iYs = stats.ptr<int>(i)[cv::CC_STAT_TOP];
......@@ -1468,9 +1499,9 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye
//<输出结果图像
tpDstImg->iWidth = showMat.cols; tpDstImg->iHeight = showMat.rows; tpDstImg->iDepth = showMat.depth(); tpDstImg->iChannels = showMat.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
int _Size = tpDstImg->iWidth * tpDstImg->iHeight * tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
tpDstImg->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
......@@ -1485,7 +1516,7 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye
bool eyemBinFree(IntPtr hObject)
{
std::vector<EyemBinBlob> *tpResult = reinterpret_cast<std::vector<EyemBinBlob>*>(hObject);
std::vector<EyemBinBlob>* tpResult = reinterpret_cast<std::vector<EyemBinBlob>*>(hObject);
delete tpResult;
tpResult = NULL;
return true;
......
......@@ -45,20 +45,20 @@ static cv::Mat projectMap(const cv::Mat map, int threshold)
return image;
}
void getSuperResolution(const cv::Mat &src, cv::Mat &dst, int size)
void getSuperResolution(const cv::Mat& src, cv::Mat& dst, int size)
{
dst = cv::Mat::zeros(src.size()*size, src.type());
dst = cv::Mat::zeros(src.size() * size, src.type());
for (int i = 0; i < src.cols; i++)
{
for (int j = 0; j < src.rows; j++)
{
cv::Mat m(cv::Size(size, size), src.type(), cv::Scalar::all(src.at<uchar>(j, i)));
m.copyTo(dst(cv::Rect(i*size, j*size, size, size)));
m.copyTo(dst(cv::Rect(i * size, j * size, size, size)));
}
}
}
int eyemEdge1dGenMeasureRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, const char *ccSubType, int iTransition, double dSigma, double dAmpThresh, IntPtr *hObject)
int eyemEdge1dGenMeasureRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, const char* ccSubType, int iTransition, double dSigma, double dAmpThresh, IntPtr* hObject)
{
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage);
......@@ -74,7 +74,7 @@ int eyemEdge1dGenMeasureRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY
return FUNC_OK;
}
int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int iTransition, double dSigma, double dAmpThresh, IntPtr *hObject)
int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int iTransition, double dSigma, double dAmpThresh, IntPtr* hObject)
{
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage);
......@@ -90,7 +90,7 @@ int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLi
return FUNC_OK;
}
int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iCapLength, int iCapWidth, int nCalipers, int nFilterSize, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject)
int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iCapLength, int iCapWidth, int nCalipers, int nFilterSize, int iSearchDirec, double dAmpThreshold, const char* ccTransition, IntPtr* hObject)
{
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty()) {
......@@ -122,13 +122,13 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
//直线上的坐标
float L = (float)cv::norm(cv::Point2d(tpLineSt.dX, tpLineSt.dY) - cv::Point2d(tpLineEd.dX, tpLineEd.dY));
//步长
float plusStep = (L - (float)nCalipers*(float)iCapWidth) / ((float)nCalipers + 1.0f);
float plusStep = (L - (float)nCalipers * (float)iCapWidth) / ((float)nCalipers + 1.0f);
//绘制profileLine
cv::arrowedLine(cc, cv::Point(cvRound(tpLineSt.dX), cvRound(tpLineSt.dY)), cv::Point(cvRound(tpLineEd.dX), cvRound(tpLineEd.dY)), cv::Scalar(255, 153, 0), 1);
//判断极性
bool anyPolarity = strcmp("all", ccTransition) == 0;
//默认过滤一半像素
float *filterK = new float[2 * nFilterSize + 1]();
float* filterK = new float[2 * nFilterSize + 1]();
//定义滤波核
for (int n = 0; n < nFilterSize; n++) {
filterK[n] = 1;
......@@ -138,32 +138,32 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
//线采样,双线性插值
cv::Size szMap(2 * iCapLength + 1, iCapWidth + 1);
//结果
std::vector<EyemOcsDXY> *tpResults = new std::vector<EyemOcsDXY>();
std::vector<EyemOcsDXY>* tpResults = new std::vector<EyemOcsDXY>();
for (int n = 1; n <= nCalipers; n++)
{
float *pMag = new float[szMap.width*szMap.height];
float* pMag = new float[szMap.width * szMap.height];
for (int m = 0; m <= iCapWidth; m++)
{
float plusX, plusY;
plusX = ((float)n*(plusStep + (float)iCapWidth) - (float)iCapWidth + m) * (float)cos(t);
plusY = ((float)n*(plusStep + (float)iCapWidth) - (float)iCapWidth + m) * (float)sin(t);
plusX = ((float)n * (plusStep + (float)iCapWidth) - (float)iCapWidth + m) * (float)cos(t);
plusY = ((float)n * (plusStep + (float)iCapWidth) - (float)iCapWidth + m) * (float)sin(t);
//中轴线路径上的点
cv::Point2f pLine((float)tpLineSt.dX + plusX, (float)tpLineSt.dY + plusY);
for (int iR = -iCapLength; iR <= iCapLength; iR++) {
//待插值坐标
float _plusX, _plusY;
_plusX = (float)iR*(float)cos(t + iSearchDirec*CV_PI / 2.0) + pLine.x;
_plusY = (float)iR*(float)sin(t + iSearchDirec*CV_PI / 2.0) + pLine.y;
_plusX = (float)iR * (float)cos(t + iSearchDirec * CV_PI / 2.0) + pLine.x;
_plusY = (float)iR * (float)sin(t + iSearchDirec * CV_PI / 2.0) + pLine.y;
//防止越界
if (_plusX < 1 || _plusX >= X - 2 || _plusY < 1 || _plusY >= Y - 2) {
pMag[(iCapLength + iR) + m*szMap.width] = -1;
pMag[(iCapLength + iR) + m * szMap.width] = -1;
continue;
}
#ifdef _DEBUG
//drawPoint("", cv::Point2f(_plusX, _plusY), cv::Scalar(36, 127, 255), 1);
//画像素
float bb = (float)cos(t)*0.5f;
float aa = (float)sin(t)*0.5f;
float bb = (float)cos(t) * 0.5f;
float aa = (float)sin(t) * 0.5f;
cv::Point2f pt(_plusX, _plusY);
cv::Point2f pts[4];
pts[0].x = (float)(pt.x - aa - bb);
......@@ -185,28 +185,29 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
float u = abs(_plusX - ((float)x + 0.5f));
float v = abs(_plusY - ((float)y - 1.0f + 0.5f));
//插值计算灰度值
float gv = (1.0f - v)*(image.ptr<uint8_t>(y - 1)[x] * (1.0f - u) + image.ptr<uint8_t>(y - 1)[x - 1] * u)
+ v*(image.ptr<uint8_t>(y)[x] * (1.0f - u) + image.ptr<uint8_t>(y)[x - 1] * u);
float gv = (1.0f - v) * (image.ptr<uint8_t>(y - 1)[x] * (1.0f - u) + image.ptr<uint8_t>(y - 1)[x - 1] * u)
+ v * (image.ptr<uint8_t>(y)[x] * (1.0f - u) + image.ptr<uint8_t>(y)[x - 1] * u);
//填入灰度值
pMag[(iCapLength + iR) + m*szMap.width] = gv;
pMag[(iCapLength + iR) + m * szMap.width] = gv;
}
}
//采样位置
cv::Point2f midLine((float)tpLineSt.dX + ((float)n*(plusStep + (float)iCapWidth) - (float)iCapWidth + (float)iCapWidth / 2.0f) * (float)cos(t),
(float)tpLineSt.dY + ((float)n*(plusStep + (float)iCapWidth) - (float)iCapWidth + (float)iCapWidth / 2.0f) * (float)sin(t));
cv::Point2f midLine((float)tpLineSt.dX + ((float)n * (plusStep + (float)iCapWidth) - (float)iCapWidth + (float)iCapWidth / 2.0f) * (float)cos(t),
(float)tpLineSt.dY + ((float)n * (plusStep + (float)iCapWidth) - (float)iCapWidth + (float)iCapWidth / 2.0f) * (float)sin(t));
//各位置采样路径
cv::Point2f midLineStart, midLineEnd;
midLineStart = cv::Point2f(-iCapLength*(float)cos(t + iSearchDirec*CV_PI / 2.0) + midLine.x, -iCapLength*(float)sin(t + iSearchDirec*CV_PI / 2.0) + midLine.y);
midLineEnd = cv::Point2f(iCapLength*(float)cos(t + iSearchDirec* CV_PI / 2) + midLine.x, iCapLength*(float)sin(t + iSearchDirec*CV_PI / 2.0) + midLine.y);
midLineStart = cv::Point2f(-iCapLength * (float)cos(t + iSearchDirec * CV_PI / 2.0) + midLine.x, -iCapLength * (float)sin(t + iSearchDirec * CV_PI / 2.0) + midLine.y);
midLineEnd = cv::Point2f(iCapLength * (float)cos(t + iSearchDirec * CV_PI / 2) + midLine.x, iCapLength * (float)sin(t + iSearchDirec * CV_PI / 2.0) + midLine.y);
//采样图像
cv::Mat interMap(szMap, CV_32FC1, pMag);
//计算投影
cv::Mat projectedMap;
cv::reduce(interMap, projectedMap, 0, cv::REDUCE_AVG, CV_32F);
//差分过滤(TODO:加高斯滤波)
float *pFilteredMap = new float[szMap.width];
float* pFilteredMap = new float[szMap.width];
cv::Mat filteredMap(cv::Size(szMap.width, 1), CV_32FC1, pFilteredMap);
cv::sepFilter2D(projectedMap, filteredMap, CV_32F, whalf, cv::Mat::ones(1, 1, CV_32F));
cv::Mat kY = cv::Mat::ones(1, 1, CV_32F);
cv::sepFilter2D(projectedMap, filteredMap, CV_32F, whalf, kY);
//投影峰值查找
std::vector<int> peeks;
findPeak(szMap.width, pFilteredMap, (float)dAmpThreshold, peeks);
......@@ -217,7 +218,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
if (anyPolarity) {
//不分极性
float maxDist = 0; int maxPos = 0; found = true;
for (auto&peek : peeks) {
for (auto& peek : peeks) {
if (abs(pFilteredMap[peek]) > maxDist) {
maxDist = abs(pFilteredMap[peek]);
maxPos = peek;
......@@ -227,7 +228,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
}
else if (strcmp("positive", ccTransition) == 0) {
int maxPos = 0;
for (auto&peek : peeks) {
for (auto& peek : peeks) {
if (pFilteredMap[peek] > 0) {
maxPos = peek;
found = true;
......@@ -238,7 +239,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
}
else if (strcmp("negative", ccTransition) == 0) {
int maxPos = 0;
for (auto&peek : peeks) {
for (auto& peek : peeks) {
if (pFilteredMap[peek] < 0) {
maxPos = peek;
found = true;
......@@ -256,11 +257,11 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
a = pFilteredMap[l]; b = pFilteredMap[m];
c = pFilteredMap[r];
u = 0.5f*(a - c) / (a - b - b + c);
u = 0.5f * (a - c) / (a - b - b + c);
//定位结果
float dstX, dstY;
dstX = midLineStart.x + (dist + u)*(float)cos(t + iSearchDirec* CV_PI / 2.0);
dstY = midLineStart.y + (dist + u)*(float)sin(t + iSearchDirec* CV_PI / 2.0);
dstX = midLineStart.x + (dist + u) * (float)cos(t + iSearchDirec * CV_PI / 2.0);
dstY = midLineStart.y + (dist + u) * (float)sin(t + iSearchDirec * CV_PI / 2.0);
EyemOcsDXY tpResult;
tpResult.dX = dstX; tpResult.dY = dstY;
tpResults->push_back(tpResult);
......@@ -269,8 +270,8 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
#ifdef _DEBUG
cv::arrowedLine(cc, midLineStart, midLineEnd, cv::Scalar(0, 255, 0), 1);
//画卡尺
float bb = (float)cos(t)*0.5f;
float aa = (float)sin(t)*0.5f;
float bb = (float)cos(t) * 0.5f;
float aa = (float)sin(t) * 0.5f;
cv::Point2f pt(midLine.x, midLine.y);
cv::Point2f pts[4];
pts[0].x = (float)(pt.x - aa * szMap.width - bb * szMap.height);
......@@ -292,26 +293,21 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
pMag = NULL;
}
#ifdef _DEBUG
if (!tpResults->empty()) {
//拟合直线
EyemOcsDABC tpLine;
eyemFitLine((int)tpResults->size(), tpResults->data(), 3, tpLine);
//画直线y=kx+b--->kx-y+b=0
//(0,P1)、(X,P2)、(P3,0)、(P4,Y)
cv::Mat dst;
getSuperResolution(image, dst, 10);
cv::cvtColor(dst, dst, cv::COLOR_GRAY2BGR);
for (int i = 0; i < tpResults->size(); i++)
{
cv::circle(dst, cv::Point(int(round(tpResults->at(i).dX * 10)), int(round(tpResults->at(i).dY * 10))), 1, cv::Scalar(0, 255, 0), -1);
}
}
#endif
//遍历结果
//for (auto it = tpResults->begin(); it != tpResults->end(); ++it)
//{
// it->dX; it->dY;
//if (!tpResults->empty()) {
// //拟合直线
// EyemOcsDABC tpLine;
// eyemFitLine((int)tpResults->size(), tpResults->data(), 3, tpLine);
// //画直线y=kx+b--->kx-y+b=0
// //(0,P1)、(X,P2)、(P3,0)、(P4,Y)
// cv::Mat dst;
// getSuperResolution(image, dst, 10);
// cv::cvtColor(dst, dst, cv::COLOR_GRAY2BGR);
// for (int i = 0; i < tpResults->size(); i++)
// {
// cv::circle(dst, cv::Point(int(round(tpResults->at(i).dX * 10)), int(round(tpResults->at(i).dY * 10))), 1, cv::Scalar(0, 255, 0), -1);
// }
//}
#endif
//释放资源(Tips:当存在越界时候在用free释放时会报错)
delete[] filterK;
filterK = NULL;
......@@ -320,7 +316,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
return FUNC_OK;
}
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)
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)
{
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty()) {
......@@ -349,7 +345,7 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
//判断极性
bool anyPolarity = strcmp("all", ccTransition) == 0;
//默认过滤一半像素
float *filterK = new float[2 * nFilterSize + 1]();
float* filterK = new float[2 * nFilterSize + 1]();
//定义滤波核
for (int n = 0; n < nFilterSize; n++) {
filterK[n] = 1;
......@@ -363,22 +359,22 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
//线采样
cv::Size szMap(2 * iCapLength + 1, iCapWidth + 1);
//结果
std::vector<EyemOcsDXY> *tpResults = new std::vector<EyemOcsDXY>();
std::vector<EyemOcsDXY>* tpResults = new std::vector<EyemOcsDXY>();
for (float t = -(float)PI; t < PI; t += plusStep)
{
int m = 0;
//路径上的点
float x = float(tpPoint.dX + (float)iRadius*cos(t));
float y = float(tpPoint.dY + (float)iRadius*sin(t));
float x = float(tpPoint.dX + (float)iRadius * cos(t));
float y = float(tpPoint.dY + (float)iRadius * sin(t));
//采样图像
float *pMag = new float[szMap.width*szMap.height];
float* pMag = new float[szMap.width * szMap.height];
for (float n = -(float)iCapWidth / 2.0f; n <= (float)iCapWidth / 2.0f; n += 1.0f, m++)
{
for (int iR = -iCapLength; iR <= iCapLength; iR++) {
//待插值坐标
float _plusX, _plusY;
_plusX = (float)iR*iSearchDirec*(float)cos(t) + x + n*(float)cos(t + CV_PI / 2);
_plusY = (float)iR*iSearchDirec*(float)sin(t) + y + n*(float)sin(t + CV_PI / 2);
_plusX = (float)iR * iSearchDirec * (float)cos(t) + x + n * (float)cos(t + CV_PI / 2);
_plusY = (float)iR * iSearchDirec * (float)sin(t) + y + n * (float)sin(t + CV_PI / 2);
//防止越界
if (_plusX < 1 || _plusX >= X - 2 || _plusY < 1 || _plusY >= Y - 2) {
continue;
......@@ -390,16 +386,16 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
float u = abs(_plusX - ((float)x + 0.5f));
float v = abs(_plusY - ((float)y - 1.0f + 0.5f));
//插值计算灰度值
float gv = (1.0f - v)*(image.ptr<uint8_t>(y - 1)[x] * (1.0f - u) + image.ptr<uint8_t>(y - 1)[x - 1] * u)
+ v*(image.ptr<uint8_t>(y)[x] * (1.0f - u) + image.ptr<uint8_t>(y)[x - 1] * u);
float gv = (1.0f - v) * (image.ptr<uint8_t>(y - 1)[x] * (1.0f - u) + image.ptr<uint8_t>(y - 1)[x - 1] * u)
+ v * (image.ptr<uint8_t>(y)[x] * (1.0f - u) + image.ptr<uint8_t>(y)[x - 1] * u);
//填入灰度值
pMag[(iCapLength + iR) + m*szMap.width] = gv;
pMag[(iCapLength + iR) + m * szMap.width] = gv;
}
}
//采样位置中线
cv::Point2f midLineStart, midLineEnd;
midLineStart = cv::Point2f(-iCapLength*iSearchDirec*(float)cos(t) + x, -iCapLength*iSearchDirec*(float)sin(t) + y);
midLineEnd = cv::Point2f(iCapLength*iSearchDirec*(float)cos(t) + x, iCapLength*iSearchDirec*(float)sin(t) + y);
midLineStart = cv::Point2f(-iCapLength * iSearchDirec * (float)cos(t) + x, -iCapLength * iSearchDirec * (float)sin(t) + y);
midLineEnd = cv::Point2f(iCapLength * iSearchDirec * (float)cos(t) + x, iCapLength * iSearchDirec * (float)sin(t) + y);
cv::arrowedLine(cc, cv::Point(), cv::Point(), cv::Scalar(0, 255, 0), 1);
//采样图像
cv::Mat interMap(szMap, CV_32FC1, pMag);
......@@ -407,7 +403,7 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
cv::Mat projectedMap;
cv::reduce(interMap, projectedMap, 0, cv::REDUCE_AVG, CV_32F);
//差分过滤(TODO:加高斯滤波)
float *pFilteredMap = new float[szMap.width];
float* pFilteredMap = new float[szMap.width];
cv::Mat filteredMap(cv::Size(szMap.width, 1), CV_32FC1, pFilteredMap);
cv::sepFilter2D(projectedMap, filteredMap, CV_32F, whalf, cv::Mat::ones(1, 1, CV_32F));
//投影峰值查找
......@@ -420,7 +416,7 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
if (anyPolarity) {
//不分极性
float maxDist = 0; int maxPos = 0;
for (auto&peek : peeks) {
for (auto& peek : peeks) {
if (abs(pFilteredMap[peek]) > maxDist) {
maxDist = abs(pFilteredMap[peek]);
maxPos = peek;
......@@ -431,7 +427,7 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
}
else if (strcmp("positive", ccTransition) == 0) {
int maxPos = 0;
for (auto&peek : peeks) {
for (auto& peek : peeks) {
if (pFilteredMap[peek] > 0) {
maxPos = peek;
found = true;
......@@ -442,7 +438,7 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
}
else if (strcmp("negative", ccTransition) == 0) {
int maxPos = 0;
for (auto&peek : peeks) {
for (auto& peek : peeks) {
if (pFilteredMap[peek] < 0) {
maxPos = peek;
found = true;
......@@ -460,12 +456,12 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
a = pFilteredMap[l]; b = pFilteredMap[m];
c = pFilteredMap[r];
u = 0.5f*(a - c) / (a - b - b + c);
u = 0.5f * (a - c) / (a - b - b + c);
//定位结果
float dstX, dstY;
dstX = midLineStart.x + iSearchDirec*(dist + u)*(float)cos(t);
dstY = midLineStart.y + iSearchDirec*(dist + u)*(float)sin(t);
dstX = midLineStart.x + iSearchDirec * (dist + u) * (float)cos(t);
dstY = midLineStart.y + iSearchDirec * (dist + u) * (float)sin(t);
EyemOcsDXY tpResult;
tpResult.dX = dstX; tpResult.dY = dstY;
tpResults->push_back(tpResult);
......@@ -473,8 +469,8 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
}
#ifdef _DEBUG
//画卡尺
float bb = (float)cos(t + CV_PI / 2)*0.5f;
float aa = (float)sin(t + CV_PI / 2)*0.5f;
float bb = (float)cos(t + CV_PI / 2) * 0.5f;
float aa = (float)sin(t + CV_PI / 2) * 0.5f;
cv::Point2f pt(x, y);
cv::Point2f pts[4];
pts[0].x = (float)(pt.x - aa * szMap.width - bb * szMap.height);
......@@ -503,7 +499,7 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
return FUNC_OK;
}
int eyemEdge1dGenArc(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int iEdgeDirec, EyemOcsDXY *tpEdge)
int eyemEdge1dGenArc(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int iEdgeDirec, EyemOcsDXY* tpEdge)
{
return FUNC_OK;
......@@ -529,30 +525,30 @@ int eyemPolarTrans(EyemImage tpImage, EyemOcsDXY tpCenter, int iRadius, int iSap
return 0;
}
//计算目标尺寸
float C = 2.0f*(float)CV_PI*(float)(iRadius + iSapWidth);
float C = 2.0f * (float)CV_PI * (float)(iRadius + iSapWidth);
//步长(角度)
float plusStep = 2.0f*asinf((1.0f + (C - (float)cvRound(C)) / (float)cvRound(C)) / (2.0f * (float)(iRadius + +iSapWidth)));
float plusStep = 2.0f * asinf((1.0f + (C - (float)cvRound(C)) / (float)cvRound(C)) / (2.0f * (float)(iRadius + +iSapWidth)));
//长度
int iSapLength = cvRound(2.0f*CV_PI / plusStep);
int iSapLength = cvRound(2.0f * CV_PI / plusStep);
//结果图像
cv::Mat polarMat(cv::Size(iSapLength, 2 * iSapWidth), CV_8UC1, cv::Scalar(0));
for (int n = iSapWidth; n > -iSapWidth; n--)
{
//周长
C = 2.0f*(float)CV_PI*(float)(iRadius + n);
C = 2.0f * (float)CV_PI * (float)(iRadius + n);
//步长(角度)
plusStep = 2.0f*asinf((1.0f + (C - (float)cvRound(C)) / (float)cvRound(C)) / (2.0f * (float)(iRadius + n)));
plusStep = 2.0f * asinf((1.0f + (C - (float)cvRound(C)) / (float)cvRound(C)) / (2.0f * (float)(iRadius + n)));
//长度
iSapLength = cvRound(2.0f*CV_PI / plusStep);
iSapLength = cvRound(2.0f * CV_PI / plusStep);
//线采样
cv::Size szMap(iSapLength, 1);
//采样图像
int m = 0; float *pPolarBuf = new float[szMap.width*szMap.height * sizeof(float_t)];
int m = 0; float* pPolarBuf = new float[szMap.width * szMap.height * sizeof(float_t)];
for (double t = -CV_PI; t < CV_PI; t += plusStep, m++)
{
//路径上的点
float _plusX = float(tpCenter.dX + (float)(iRadius + n)*cos(t));
float _plusY = float(tpCenter.dY + (float)(iRadius + n)*sin(t));
float _plusX = float(tpCenter.dX + (float)(iRadius + n) * cos(t));
float _plusY = float(tpCenter.dY + (float)(iRadius + n) * sin(t));
//防止越界
if (_plusX < 1 || _plusX >= X - 2 || _plusY < 1 || _plusY >= Y - 2) {
continue;
......@@ -563,8 +559,8 @@ int eyemPolarTrans(EyemImage tpImage, EyemOcsDXY tpCenter, int iRadius, int iSap
float u = abs(_plusX - ((float)x + 0.5f));
float v = abs(_plusY - ((float)y - 1.0f + 0.5f));
//插值计算灰度值
float gv = (1.0f - v)*(image.ptr<uint8_t>(y - 1)[x] * (1.0f - u) + image.ptr<uint8_t>(y - 1)[x - 1] * u)
+ v*(image.ptr<uint8_t>(y)[x] * (1.0f - u) + image.ptr<uint8_t>(y)[x - 1] * u);
float gv = (1.0f - v) * (image.ptr<uint8_t>(y - 1)[x] * (1.0f - u) + image.ptr<uint8_t>(y - 1)[x - 1] * u)
+ v * (image.ptr<uint8_t>(y)[x] * (1.0f - u) + image.ptr<uint8_t>(y)[x - 1] * u);
//填入灰度值
pPolarBuf[m] = gv;
}
......@@ -588,7 +584,7 @@ int eyemPolarTrans(EyemImage tpImage, EyemOcsDXY tpCenter, int iRadius, int iSap
bool eyemEdge1dGenFree(IntPtr hObject)
{
std::vector<EyemOcsDXY> *tpEdges = reinterpret_cast<std::vector<EyemOcsDXY>*>(hObject);
std::vector<EyemOcsDXY>* tpEdges = reinterpret_cast<std::vector<EyemOcsDXY>*>(hObject);
delete tpEdges;
tpEdges = NULL;
return true;
......
......@@ -7,5 +7,6 @@
#include "eyemLib.h"
int eyemEdge1dFindLineInner(cv::Mat& image, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iCapLength, int iCapWidth, int nCalipers, int nFilterSize, int iSearchDirec, double dAmpThreshold, const char* ccTransition, std::vector<EyemOcsDXY>& hObject);
#endif/* __EYEM_EDGE1D_H */
\ No newline at end of file
......@@ -5,7 +5,7 @@ public:
Impl() {}
~Impl() {}
//ȡ
std::vector<float> forward(const cv::Mat& img, cv::Scalar mean, cv::Scalar std);
std::vector<float> forward(cv::Mat& img, cv::Scalar mean, cv::Scalar std);
//ȡ
std::shared_ptr<AZONNXWrapper> extractor_;
};
......@@ -28,7 +28,7 @@ std::vector<float> Extractor::extract(cv::InputArray img)
}
std::vector<float> Extractor::Impl::forward(const cv::Mat& img, cv::Scalar mean, cv::Scalar std)
std::vector<float> Extractor::Impl::forward(cv::Mat& img, cv::Scalar mean, cv::Scalar std)
{
std::vector<float> predictions(512);
float* outputs = extractor_->forward(img, mean, std);
......
......@@ -7,10 +7,10 @@ static double calcDist(const EyemOcsDXY2D taPoint1, const EyemOcsDXYR taPoint2)
static double calcDist2D(const EyemOcsDXY2D taPointP, double dA, double dB, double dC)
{
return abs(dA*taPointP.dX + dB*taPointP.dY + dC) / sqrt(dA*dA + dB*dB);
return abs(dA * taPointP.dX + dB * taPointP.dY + dC) / sqrt(dA * dA + dB * dB);
}
static void weightL1(float *d, int count, float *w, float _c)
static void weightL1(float* d, int count, float* w, float _c)
{
int i;
......@@ -21,7 +21,7 @@ static void weightL1(float *d, int count, float *w, float _c)
}
}
static void weightL12(float *d, int count, float *w, float _c)
static void weightL12(float* d, int count, float* w, float _c)
{
int i;
......@@ -31,7 +31,7 @@ static void weightL12(float *d, int count, float *w, float _c)
}
}
static void weightFair(float *d, int count, float *w, float _c)
static void weightFair(float* d, int count, float* w, float _c)
{
int i;
const float c = _c == 0 ? 1 / 1.3998f : 1 / _c;
......@@ -42,7 +42,7 @@ static void weightFair(float *d, int count, float *w, float _c)
}
}
static void weightWelsch(float *d, int count, float *w, float _c)
static void weightWelsch(float* d, int count, float* w, float _c)
{
int i;
const float c = _c == 0 ? 1 / 2.9846f : 1 / _c;
......@@ -53,7 +53,7 @@ static void weightWelsch(float *d, int count, float *w, float _c)
}
}
static void weightHuber(float *d, int count, float *w, float _c)
static void weightHuber(float* d, int count, float* w, float _c)
{
int i;
const float c = _c <= 0 ? 1.345f : _c;
......@@ -67,7 +67,7 @@ static void weightHuber(float *d, int count, float *w, float _c)
}
}
static void weightTukey(float *d, int count, float *w, float _c)
static void weightTukey(float* d, int count, float* w, float _c)
{
int i;
......@@ -76,13 +76,13 @@ static void weightTukey(float *d, int count, float *w, float _c)
for (i = 0; i < count; i++)
{
if (d[i] < c)
w[i] = std::pow(1.0f - (d[i] / c)*(d[i] / c), 2);
w[i] = std::pow(1.0f - (d[i] / c) * (d[i] / c), 2);
else
w[i] = .0f;
}
}
static void weightCauchy(float *d, int count, float *w, float _c)
static void weightCauchy(float* d, int count, float* w, float _c)
{
int i;
const float c = _c == 0 ? 1 / 2.385f : 1 / _c;
......@@ -90,14 +90,14 @@ static void weightCauchy(float *d, int count, float *w, float _c)
for (i = 0; i < count; i++)
{
if (d[i] < c)
w[i] = 1 / (1 + d[i] * d[i] * c*c);
w[i] = 1 / (1 + d[i] * d[i] * c * c);
else
w[i] = .0;
}
}
static void weightLogistic(float *d, int count, float *w, float _c)
static void weightLogistic(float* d, int count, float* w, float _c)
{
int i;
const float c = _c == 0 ? 1 / 1.205f : 1 / _c;
......@@ -112,7 +112,7 @@ static void weightLogistic(float *d, int count, float *w, float _c)
}
}
static void weightAndrews(float *d, int count, float *w, float _c)
static void weightAndrews(float* d, int count, float* w, float _c)
{
int i;
const float c = _c == 0 ? 1 / 1.339f : 1 / _c;
......@@ -127,7 +127,7 @@ static void weightAndrews(float *d, int count, float *w, float _c)
}
}
static void weightTalworth(float *d, int count, float *w, float _c)
static void weightTalworth(float* d, int count, float* w, float _c)
{
int i;
const float c = _c == 0 ? 2.795f : _c;
......@@ -142,7 +142,7 @@ static void weightTalworth(float *d, int count, float *w, float _c)
}
}
static void weightUser(float *d, int count, float *w, float _c)
static void weightUser(float* d, int count, float* w, float _c)
{
int i;
......@@ -151,13 +151,13 @@ static void weightUser(float *d, int count, float *w, float _c)
for (i = 0; i < count; i++)
{
if (d[i] < c)
w[i] = pow(1.0f - (d[i] / c)*(d[i] / c), 2);
w[i] = pow(1.0f - (d[i] / c) * (d[i] / c), 2);
else
w[i] = .0;
}
}
static void fitLine2D_wods(int iPtnNum, const EyemOcsDXY *taPoints, float *weights, float *line)
static void fitLine2D_wods(int iPtnNum, const EyemOcsDXY* taPoints, float* weights, float* line)
{
double px = .0, py = .0, w = .0;
double sa[4], sb[2], sx[2];
......@@ -171,10 +171,10 @@ static void fitLine2D_wods(int iPtnNum, const EyemOcsDXY *taPoints, float *weigh
for (int i = 0; i < iPtnNum; i++) {
sa[0] += weights[i];
sa[1] += weights[i] * taPoints[i].dX;
sa[3] += weights[i] * taPoints[i].dX*taPoints[i].dX;
sa[3] += weights[i] * taPoints[i].dX * taPoints[i].dX;
sb[0] += weights[i] * taPoints[i].dY;
sb[1] += weights[i] * taPoints[i].dX*taPoints[i].dY;
sb[1] += weights[i] * taPoints[i].dX * taPoints[i].dY;
w += weights[i];
}
......@@ -191,10 +191,10 @@ static void fitLine2D_wods(int iPtnNum, const EyemOcsDXY *taPoints, float *weigh
line[3] = (float)py;
}
int eyemRobustFitLine(int iPtnNum, EyemOcsDXY *taPoints, int iCalcMode, double dRobustCoef, EyemOcsDABC &tpLine)
int eyemRobustFitLine(int iPtnNum, EyemOcsDXY* taPoints, int iCalcMode, double dRobustCoef, EyemOcsDABC& tpLine)
{
double min_err = DBL_MAX, err = 0;
void(*calc_weights_param) (float *, int, float *, float) = 0;
void(*calc_weights_param) (float*, int, float*, float) = 0;
float linebuf[4] = { .0f };
memset(linebuf, 0, 4 * sizeof(float));
......@@ -248,7 +248,7 @@ int eyemRobustFitLine(int iPtnNum, EyemOcsDXY *taPoints, int iCalcMode, double d
cv::AutoBuffer<float> dist(iPtnNum);
for (int k = 0; k < iPtnNum; k++) {
dist[k] = fabs(nx*(float)taPoints[k].dX + ny*(float)taPoints[k].dY - (nx*px + ny*py)) / sqrt(nx*nx + ny*ny);
dist[k] = fabs(nx * (float)taPoints[k].dX + ny * (float)taPoints[k].dY - (nx * px + ny * py)) / sqrt(nx * nx + ny * ny);
sum_dist += dist[k];
}
err = sum_dist;
......@@ -265,11 +265,11 @@ int eyemRobustFitLine(int iPtnNum, EyemOcsDXY *taPoints, int iCalcMode, double d
//直线一般式
tpLine.dA = nx;
tpLine.dB = ny;
tpLine.dC = -(nx*px + ny*py);
tpLine.dC = -(nx * px + ny * py);
return FUNC_OK;
}
static void fitLine2D_wods(int iPtnNum, const EyemOcsDXY2D *taPoints, EyemOcsDABC &tpLine)
static void fitLine2D_wods(int iPtnNum, const EyemOcsDXY2D* taPoints, EyemOcsDABC& tpLine)
{
std::vector<cv::Point2f> points;
for (int i = 0; i < iPtnNum; i++) {
......@@ -284,10 +284,10 @@ static void fitLine2D_wods(int iPtnNum, const EyemOcsDXY2D *taPoints, EyemOcsDAB
//直线一般式
tpLine.dA = nx;
tpLine.dB = ny;
tpLine.dC = -(nx*px + ny*py);
tpLine.dC = -(nx * px + ny * py);
}
int eyemFitLine(int iPtnNum, EyemOcsDXY *taPoint, int iNumToIgnore, EyemOcsDABC &tpLine)
int eyemFitLine(int iPtnNum, EyemOcsDXY* taPoint, int iNumToIgnore, EyemOcsDABC& tpLine)
{
if (iPtnNum - iNumToIgnore < 2 || iPtnNum < 2) {
return FUNC_CANNOT_CALC;
......@@ -334,7 +334,7 @@ int eyemFitLine(int iPtnNum, EyemOcsDXY *taPoint, int iNumToIgnore, EyemOcsDABC
return FUNC_OK;
}
int eyemFitLineRANSAC(int iPtnNum, EyemOcsDXY *taPoint, double dClippingFactor, EyemOcsDABC &tpLine)
int eyemFitLineRANSAC(int iPtnNum, EyemOcsDXY* taPoint, double dClippingFactor, EyemOcsDABC& tpLine)
{
int iterations = 0;
const int maxIterations = 1000;
......@@ -357,7 +357,7 @@ int eyemFitLineRANSAC(int iPtnNum, EyemOcsDXY *taPoint, double dClippingFactor,
std::vector<cv::Point2d> samplesPts(2);
for (int i = 0; i < 1000; i++) {
for (int j = 0; j < 2; j++) {
srand((i + 100)*(j + 20) + (iterations + 39) * 100);
srand((i + 100) * (j + 20) + (iterations + 39) * 100);
int iRand = rand();
samples[j] = shuffledIndices[iRand % (shuffledIndices.size() - 1)];
}
......@@ -374,15 +374,15 @@ int eyemFitLineRANSAC(int iPtnNum, EyemOcsDXY *taPoint, double dClippingFactor,
//计算直线参数
mTpLine.dA = -(samplesPts[0].y - samplesPts[1].y);
mTpLine.dB = (samplesPts[0].x - samplesPts[1].x);
mTpLine.dC = samplesPts[1].x*samplesPts[0].y - samplesPts[0].x*samplesPts[1].y;
mTpLine.dC = samplesPts[1].x * samplesPts[0].y - samplesPts[0].x * samplesPts[1].y;
//判断大部分是否已经计算过(这样可以减少计算时间,但可能会不准)
int nSkippedCount = 0, nInliersCcount(0);
for (auto&p : taPoints) {
for (auto& p : taPoints) {
if (p.bValid) {
nSkippedCount++;
}
double dpDist = std::abs(mTpLine.dA*p.dX + mTpLine.dB*p.dY + mTpLine.dC) / sqrt(mTpLine.dA*mTpLine.dA + mTpLine.dB*mTpLine.dB);
double dpDist = std::abs(mTpLine.dA * p.dX + mTpLine.dB * p.dY + mTpLine.dC) / sqrt(mTpLine.dA * mTpLine.dA + mTpLine.dB * mTpLine.dB);
if (dpDist < dClippingFactor) {
nInliersCcount++;
}
......@@ -400,7 +400,7 @@ int eyemFitLineRANSAC(int iPtnNum, EyemOcsDXY *taPoint, double dClippingFactor,
return FUNC_OK;
}
static void fitCircle2D_wods(int iPtnNum, const EyemOcsDXY2D *taPoints, EyemOcsDXYR &tpCircle)
static void fitCircle2D_wods(int iPtnNum, const EyemOcsDXY2D* taPoints, EyemOcsDXYR& tpCircle)
{
std::vector<cv::Point2d> points;
for (int i = 0; i < iPtnNum; i++) {
......@@ -419,12 +419,12 @@ static void fitCircle2D_wods(int iPtnNum, const EyemOcsDXY2D *taPoints, EyemOcsD
sa[0] += (double)points[i].x;
sa[1] += (double)points[i].y;
sa[2] += 1.0;
sa[3] += (double)points[i].x*(double)points[i].x;
sa[4] += (double)points[i].x*(double)points[i].y;
sa[7] += (double)points[i].y*(double)points[i].y;
sa[3] += (double)points[i].x * (double)points[i].x;
sa[4] += (double)points[i].x * (double)points[i].y;
sa[7] += (double)points[i].y * (double)points[i].y;
sb[1] += (double)points[i].x*(-(double)points[i].x*(double)points[i].x - (double)points[i].y*(double)points[i].y);
sb[2] += (double)points[i].y*(-(double)points[i].x*(double)points[i].x - (double)points[i].y*(double)points[i].y);
sb[1] += (double)points[i].x * (-(double)points[i].x * (double)points[i].x - (double)points[i].y * (double)points[i].y);
sb[2] += (double)points[i].y * (-(double)points[i].x * (double)points[i].x - (double)points[i].y * (double)points[i].y);
}
sa[5] = sa[0];
sa[6] = sa[4];
......@@ -433,10 +433,10 @@ static void fitCircle2D_wods(int iPtnNum, const EyemOcsDXY2D *taPoints, EyemOcsD
cv::solve(a, b, x, cv::DECOMP_SVD);
tpCircle.dX = -x.ptr<double_t>(0)[0] / 2.0;
tpCircle.dY = -x.ptr<double_t>(1)[0] / 2.0;
tpCircle.dR = sqrt(pow(x.ptr<double_t>(0)[0], 2) + pow(x.ptr<double_t>(1)[0], 2) - 4.0*(x.ptr<double_t>(2)[0])) / 2.0;
tpCircle.dR = sqrt(pow(x.ptr<double_t>(0)[0], 2) + pow(x.ptr<double_t>(1)[0], 2) - 4.0 * (x.ptr<double_t>(2)[0])) / 2.0;
}
int eyemFitCircle(int iPtnNum, EyemOcsDXY *taPoint, int iNumToIgnore, double &dRMS, EyemOcsDXYR &tpCircle)
int eyemFitCircle(int iPtnNum, EyemOcsDXY* taPoint, int iNumToIgnore, double& dRMS, EyemOcsDXYR& tpCircle)
{
if (iPtnNum - iNumToIgnore < 3 || iPtnNum < 3) {
return FUNC_CANNOT_CALC;
......@@ -482,7 +482,7 @@ int eyemFitCircle(int iPtnNum, EyemOcsDXY *taPoint, int iNumToIgnore, double &dR
return FUNC_OK;
}
static void fitCircle2D_wods(int iPtnNum, const EyemOcsDXY *taPoints, float *weights, float *linebuf)
static void fitCircle2D_wods(int iPtnNum, const EyemOcsDXY* taPoints, float* weights, float* linebuf)
{
//计算系数
double sa[9], sb[3], sx[3];
......@@ -496,12 +496,12 @@ static void fitCircle2D_wods(int iPtnNum, const EyemOcsDXY *taPoints, float *wei
sa[0] += (double)weights[i] * taPoints[i].dX;
sa[1] += (double)weights[i] * taPoints[i].dY;
sa[2] += (double)weights[i];
sa[3] += (double)weights[i] * taPoints[i].dX*taPoints[i].dX;
sa[4] += (double)weights[i] * taPoints[i].dX*taPoints[i].dY;
sa[7] += (double)weights[i] * taPoints[i].dY*taPoints[i].dY;
sa[3] += (double)weights[i] * taPoints[i].dX * taPoints[i].dX;
sa[4] += (double)weights[i] * taPoints[i].dX * taPoints[i].dY;
sa[7] += (double)weights[i] * taPoints[i].dY * taPoints[i].dY;
sb[1] += (double)weights[i] * taPoints[i].dX*(-(double)taPoints[i].dX*(double)taPoints[i].dX - (double)taPoints[i].dY*(double)taPoints[i].dY);
sb[2] += (double)weights[i] * taPoints[i].dY*(-(double)taPoints[i].dX*(double)taPoints[i].dX - (double)taPoints[i].dY*(double)taPoints[i].dY);
sb[1] += (double)weights[i] * taPoints[i].dX * (-(double)taPoints[i].dX * (double)taPoints[i].dX - (double)taPoints[i].dY * (double)taPoints[i].dY);
sb[2] += (double)weights[i] * taPoints[i].dY * (-(double)taPoints[i].dX * (double)taPoints[i].dX - (double)taPoints[i].dY * (double)taPoints[i].dY);
}
sa[5] = sa[0];
sa[6] = sa[4];
......@@ -509,15 +509,15 @@ static void fitCircle2D_wods(int iPtnNum, const EyemOcsDXY *taPoints, float *wei
sb[0] = -(sa[3] + sa[7]);
cv::solve(a, b, x, cv::DECOMP_SVD);
linebuf[0] = -0.5f*(float)sx[0];
linebuf[1] = -0.5f*(float)sx[1];
linebuf[2] = 0.5f*sqrtf(powf((float)sx[0], 2) + powf((float)sx[1], 2) - 4.0f*(float)sx[2]);
linebuf[0] = -0.5f * (float)sx[0];
linebuf[1] = -0.5f * (float)sx[1];
linebuf[2] = 0.5f * sqrtf(powf((float)sx[0], 2) + powf((float)sx[1], 2) - 4.0f * (float)sx[2]);
}
int eyemRobustFitCircle(int iPtnNum, EyemOcsDXY *taPoints, int iCalcMode, double dRobustCoef, EyemOcsDXYR &tpCircle)
int eyemRobustFitCircle(int iPtnNum, EyemOcsDXY* taPoints, int iCalcMode, double dRobustCoef, EyemOcsDXYR& tpCircle)
{
double min_err = DBL_MAX, err = 0;
void(*calc_weights_param) (float *, int, float *, float) = 0;
void(*calc_weights_param) (float*, int, float*, float) = 0;
float linebuf[3] = { .0f };
memset(linebuf, 0, 3 * sizeof(float));
......@@ -588,53 +588,108 @@ int eyemRobustFitCircle(int iPtnNum, EyemOcsDXY *taPoints, int iCalcMode, double
return FUNC_OK;
}
int eyemFitRTMatrix(int iPtnNum, EyemOcsDXY *taPointA, EyemOcsDXY *taPointB, EyemRigidMatrix &dpResult)
int eyemFitRTMatrix(int iPtnNum, bool bFullAffine, EyemOcsDXY* taPointA, EyemOcsDXY* taPointB, EyemRigidMatrix& dpResult)
{
double sa[36], sb[6], sx[6];
cv::Mat a = cv::Mat(6, 6, CV_64F, sa), b = cv::Mat(6, 1, CV_64F, sb);
cv::Mat x = cv::Mat(6, 1, CV_64F, sx);
memset(sa, 0, sizeof(sa));
memset(sb, 0, sizeof(sb));
memset(sx, 0, sizeof(sx));
for (int i = 0; i < iPtnNum; i++)
cv::Mat mtx(2, 3, CV_64FC1);
if (bFullAffine)
{
sa[0] += taPointA[i].dX*taPointA[i].dX;
sa[1] += taPointA[i].dY*taPointA[i].dX;
sa[2] += taPointA[i].dX;
sa[6] += taPointA[i].dX*taPointA[i].dY;
sa[7] += taPointA[i].dY*taPointA[i].dY;
sa[8] += taPointA[i].dY;
sa[12] += taPointA[i].dX;
sa[13] += taPointA[i].dY;
sa[14] += 1.0;
sb[0] += taPointA[i].dX*taPointB[i].dX;
sb[1] += taPointA[i].dY*taPointB[i].dX;
sb[2] += taPointB[i].dX;
sb[3] += taPointA[i].dX*taPointB[i].dY;
sb[4] += taPointA[i].dY*taPointB[i].dY;
sb[5] += taPointB[i].dY;
}
sa[21] = sa[0];
sa[22] = sa[1];
sa[23] = sa[2];
sa[27] = sa[6];
sa[28] = sa[7];
sa[29] = sa[8];
sa[33] = sa[12];
sa[34] = sa[13];
sa[35] = sa[14];
cv::solve(a, b, x, cv::DECOMP_SVD);
double sa[36], sb[6];
cv::Mat A = cv::Mat(6, 6, CV_64F, sa), B = cv::Mat(6, 1, CV_64F, sb);
cv::Mat dst = cv::Mat(6, 1, CV_64F, mtx.data);
int i;
memset(sa, 0, sizeof(sa));
memset(sb, 0, sizeof(sb));
for (i = 0; i < iPtnNum; i++)
{
sa[0] += taPointA[i].dX * taPointA[i].dX;
sa[1] += taPointA[i].dY * taPointA[i].dX;
sa[2] += taPointA[i].dX;
sa[6] += taPointA[i].dX * taPointA[i].dY;
sa[7] += taPointA[i].dY * taPointA[i].dY;
sa[8] += taPointA[i].dY;
sa[12] += taPointA[i].dX;
sa[13] += taPointA[i].dY;
sa[14] += 1;
sb[0] += taPointA[i].dX * taPointB[i].dX;
sb[1] += taPointA[i].dY * taPointB[i].dX;
sb[2] += taPointB[i].dX;
sb[3] += taPointA[i].dX * taPointB[i].dY;
sb[4] += taPointA[i].dY * taPointB[i].dY;
sb[5] += taPointB[i].dY;
}
sa[21] = sa[0];
sa[22] = sa[1];
sa[23] = sa[2];
sa[27] = sa[6];
sa[28] = sa[7];
sa[29] = sa[8];
sa[33] = sa[12];
sa[34] = sa[13];
sa[35] = sa[14];
solve(A, B, dst, cv::DECOMP_SVD);
}
else
{
double sa[16], sb[4], m[4];
cv::Mat A = cv::Mat(4, 4, CV_64F, sa), B = cv::Mat(4, 1, CV_64F, sb);
cv::Mat dst = cv::Mat(4, 1, CV_64F, m);
int i;
memset(sa, 0, sizeof(sa));
memset(sb, 0, sizeof(sb));
for (i = 0; i < iPtnNum; i++)
{
sa[0] += taPointA[i].dX * taPointA[i].dX + taPointA[i].dY * taPointA[i].dY;
sa[1] += 0;
sa[2] += taPointA[i].dX;
sa[3] += taPointA[i].dY;
sa[4] += 0;
sa[5] += taPointA[i].dX * taPointA[i].dX + taPointA[i].dY * taPointA[i].dY;
sa[6] += -taPointA[i].dY;
sa[7] += taPointA[i].dX;
sa[8] += taPointA[i].dX;
sa[9] += -taPointA[i].dY;
sa[10] += 1;
sa[11] += 0;
sa[12] += taPointA[i].dY;
sa[13] += taPointA[i].dX;
sa[14] += 0;
sa[15] += 1;
sb[0] += taPointA[i].dX * taPointB[i].dX + taPointA[i].dY * taPointB[i].dY;
sb[1] += taPointA[i].dX * taPointB[i].dY - taPointA[i].dY * taPointB[i].dX;
sb[2] += taPointB[i].dX;
sb[3] += taPointB[i].dY;
}
dpResult.a00 = x.at<double>(0, 0); dpResult.a01 = x.at<double>(0, 1); dpResult.b00 = x.at<double>(0, 2);
dpResult.a10 = x.at<double>(1, 0); dpResult.a11 = x.at<double>(1, 1); dpResult.b10 = x.at<double>(1, 2);
solve(A, B, dst, cv::DECOMP_SVD);
mtx.at<double>(0, 0) = mtx.at<double>(1, 1) = m[0];
mtx.at<double>(0, 1) = -m[1];
mtx.at<double>(1, 0) = m[1];
mtx.at<double>(0, 2) = m[2];
mtx.at<double>(1, 2) = m[3];
}
dpResult.a00 = mtx.at<double>(0, 0);
dpResult.a01 = mtx.at<double>(0, 1);
dpResult.a10 = mtx.at<double>(1, 0);
dpResult.a11 = mtx.at<double>(1, 1);
dpResult.b00 = mtx.at<double>(0, 2);
dpResult.b10 = mtx.at<double>(1, 2);
return FUNC_OK;
}
static void fitPlane_wods(int iPtnNum, const EyemOcsDXYZ *taPoints, float *weights, float *linebuf)
static void fitPlane_wods(int iPtnNum, const EyemOcsDXYZ* taPoints, float* weights, float* linebuf)
{
//计算系数(z=ax+by+z)
double sa[9], sb[3], sx[3];
......@@ -646,16 +701,16 @@ static void fitPlane_wods(int iPtnNum, const EyemOcsDXYZ *taPoints, float *weigh
memset(sx, 0, sizeof(sx));
for (int i = 0; i < iPtnNum; i++)
{
sa[0] += (double)weights[i] * taPoints[i].dX*taPoints[i].dX;
sa[1] += (double)weights[i] * taPoints[i].dX*taPoints[i].dY;
sa[0] += (double)weights[i] * taPoints[i].dX * taPoints[i].dX;
sa[1] += (double)weights[i] * taPoints[i].dX * taPoints[i].dY;
sa[2] += (double)weights[i] * taPoints[i].dX;
sa[4] += (double)weights[i] * taPoints[i].dY*taPoints[i].dY;
sa[4] += (double)weights[i] * taPoints[i].dY * taPoints[i].dY;
sa[5] += (double)weights[i] * taPoints[i].dY;
sa[8] += (double)weights[i];
sb[0] += (double)weights[i] * taPoints[i].dX*taPoints[i].dZ;
sb[1] += (double)weights[i] * taPoints[i].dY*taPoints[i].dZ;
sb[0] += (double)weights[i] * taPoints[i].dX * taPoints[i].dZ;
sb[1] += (double)weights[i] * taPoints[i].dY * taPoints[i].dZ;
sb[2] += (double)weights[i] * taPoints[i].dZ;
}
sa[3] = sa[1];
......@@ -668,10 +723,10 @@ static void fitPlane_wods(int iPtnNum, const EyemOcsDXYZ *taPoints, float *weigh
linebuf[2] = (float)sx[2];
}
int eyemRobustFitPlane(int iPtnNum, EyemOcsDXYZ *taPoint, int iCalcMode, double dRobustCoef, EyemOcsDABCD &tpPlane)
int eyemRobustFitPlane(int iPtnNum, EyemOcsDXYZ* taPoint, int iCalcMode, double dRobustCoef, EyemOcsDABCD& tpPlane)
{
double min_err = DBL_MAX, err = 0;
void(*calc_weights_param) (float *, int, float *, float) = 0;
void(*calc_weights_param) (float*, int, float*, float) = 0;
float linebuf[3] = { .0f };
memset(linebuf, 0, 3 * sizeof(float));
......@@ -725,7 +780,7 @@ int eyemRobustFitPlane(int iPtnNum, EyemOcsDXYZ *taPoint, int iCalcMode, double
cv::AutoBuffer<float> dist(iPtnNum);
for (int k = 0; k < iPtnNum; k++) {
dist[k] = fabs((a*(float)taPoint[k].dX + b*(float)taPoint[k].dY - (float)taPoint[k].dZ + c) / (sqrt(a*a + b*b + 1)));
dist[k] = fabs((a * (float)taPoint[k].dX + b * (float)taPoint[k].dY - (float)taPoint[k].dZ + c) / (sqrt(a * a + b * b + 1)));
sum_dist += dist[k];
}
err = sum_dist;
......@@ -741,7 +796,7 @@ int eyemRobustFitPlane(int iPtnNum, EyemOcsDXYZ *taPoint, int iCalcMode, double
return FUNC_OK;
}
static void fitEllipse_wods(int iPtnNum, const EyemOcsDXY *taPoints, float *weights, float *linebuf)
static void fitEllipse_wods(int iPtnNum, const EyemOcsDXY* taPoints, float* weights, float* linebuf)
{
//6%左右的点不要
std::vector<cv::Point2f> taPoint;
......@@ -753,10 +808,10 @@ static void fitEllipse_wods(int iPtnNum, const EyemOcsDXY *taPoints, float *weig
//拟合椭圆
auto rbox = cv::fitEllipse(taPoint);
//结果
linebuf[0] = rbox.center.x; linebuf[1] = rbox.center.y; linebuf[2] = cv::max(rbox.size.width / 2.0f, rbox.size.height / 2.0f); linebuf[3] = cv::min(rbox.size.width / 2.0f, rbox.size.height / 2.0f); linebuf[4] = rbox.angle*(float)PI / 180.0f;
linebuf[0] = rbox.center.x; linebuf[1] = rbox.center.y; linebuf[2] = cv::max(rbox.size.width / 2.0f, rbox.size.height / 2.0f); linebuf[3] = cv::min(rbox.size.width / 2.0f, rbox.size.height / 2.0f); linebuf[4] = rbox.angle * (float)PI / 180.0f;
}
int eyemRobustFitEllipse(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, double dRobustCoef, EyemOcsDXYLSQ &tpEllipse)
int eyemRobustFitEllipse(int iPtnNum, EyemOcsDXY* taPoint, int iCalcMode, double dRobustCoef, EyemOcsDXYLSQ& tpEllipse)
{
float linebuf[5] = { .0f };
memset(linebuf, 0, 5 * sizeof(float));
......@@ -766,19 +821,19 @@ int eyemRobustFitEllipse(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, double
float sum_dist = .0, sum_w = .0;
fitEllipse_wods(iPtnNum, taPoint, &weights[0], linebuf);
//椭圆参数
float x0 = linebuf[0], y0 = linebuf[1], l = linebuf[2], s = linebuf[3], t = linebuf[4], c = sqrt(abs(l*l - s*s));
float x0 = linebuf[0], y0 = linebuf[1], l = linebuf[2], s = linebuf[3], t = linebuf[4], c = sqrt(abs(l * l - s * s));
//焦点
cv::Point2f F1(x0 - c*cos(t), y0 - c*sin(t)), F2(x0 + c*cos(t), y0 + c*sin(t));
cv::Point2f F1(x0 - c * cos(t), y0 - c * sin(t)), F2(x0 + c * cos(t), y0 + c * sin(t));
std::vector<float> dist(iPtnNum);
for (int k = 0; k < iPtnNum; k++) {
dist[k] = fabs(((float)cv::norm(cv::Point2f((float)taPoint[k].dX, (float)taPoint[k].dY) - F1) + (float)cv::norm(cv::Point2f((float)taPoint[k].dX, (float)taPoint[k].dY) - F2)) - 2.0f*l);
dist[k] = fabs(((float)cv::norm(cv::Point2f((float)taPoint[k].dX, (float)taPoint[k].dY) - F1) + (float)cv::norm(cv::Point2f((float)taPoint[k].dX, (float)taPoint[k].dY) - F2)) - 2.0f * l);
sum_dist += dist[k];
}
tpEllipse.dL = linebuf[2], tpEllipse.dS = linebuf[3], tpEllipse.dQ = linebuf[4], tpEllipse.dXo = linebuf[0], tpEllipse.dYo = linebuf[1];
return FUNC_OK;
}
int eyemRobustFitRectangle(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, double dRobustCoef, EyemRotateRect &tpRect)
int eyemRobustFitRectangle(int iPtnNum, EyemOcsDXY* taPoint, int iCalcMode, double dRobustCoef, EyemRotateRect& tpRect)
{
//先计算最小外包,然后计算各点到矩形的最小平方差和
//cv::minAreaRect();
......
......@@ -10,7 +10,7 @@ void eyemFreeMemBlock(void* block)
free(block);
}
int eyemImageRead(const char *fileName, int iFlag, EyemImage *tpImage)
int eyemImageRead(const char* fileName, int iFlag, EyemImage* tpImage)
{
cv::Mat _src = cv::imread(fileName, iFlag);
if (_src.empty())
......@@ -25,55 +25,55 @@ int eyemImageRead(const char *fileName, int iFlag, EyemImage *tpImage)
//图像信息
tpImage->iWidth = _src.cols; tpImage->iHeight = _src.rows; tpImage->iDepth = _src.depth(); tpImage->iChannels = _src.channels();
//内存尺寸
int _Size = tpImage->iWidth*tpImage->iHeight*tpImage->iChannels;
int _Size = tpImage->iWidth * tpImage->iHeight * tpImage->iChannels;
//申请内存
switch (tpImage->iDepth)
{
case CV_8U:
_Size *= sizeof(uint8_t);
tpImage->vpImage = (uint8_t *)malloc(_Size);
tpImage->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_8S:
_Size *= sizeof(int8_t);
tpImage->vpImage = (int8_t *)malloc(_Size);
tpImage->vpImage = (int8_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_16U:
_Size *= sizeof(uint16_t);
tpImage->vpImage = (uint16_t *)malloc(_Size);
tpImage->vpImage = (uint16_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_16S:
_Size *= sizeof(int16_t);
tpImage->vpImage = (int16_t *)malloc(_Size);
tpImage->vpImage = (int16_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_32S:
_Size *= sizeof(int32_t);
tpImage->vpImage = (int32_t *)malloc(_Size);
tpImage->vpImage = (int32_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_32F:
_Size *= sizeof(float_t);
tpImage->vpImage = (float_t *)malloc(_Size);
tpImage->vpImage = (float_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_64F:
_Size *= sizeof(double_t);
tpImage->vpImage = (double_t *)malloc(_Size);
tpImage->vpImage = (double_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
......@@ -87,30 +87,30 @@ int eyemImageRead(const char *fileName, int iFlag, EyemImage *tpImage)
return FUNC_OK;
}
int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, EyemImage *tpImage)
int eyemImageReadRaw(const char* filename, int iWidth, int iHeight, int iDepth, EyemImage* tpImage)
{
if (std::strlen(filename) == 0)
return FUNC_IMAGE_NOT_EXIST;
//
//tpImage->iChannels = 1; tpImage->iDepth = 2; tpImage->iWidth = iWidth; tpImage->iHeight = iHeight;
FILE *fp = fopen(filename, "rb+");
FILE* fp = fopen(filename, "rb+");
if (NULL != fp)
{
switch (iDepth)
{
case CV_8U:
tpImage->vpImage = (uint8_t *)malloc(iWidth*iHeight * sizeof(uint8_t));
tpImage->vpImage = (uint8_t*)malloc(iWidth * iHeight * sizeof(uint8_t));
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, iWidth*iHeight * sizeof(uint8_t));
fread(tpImage->vpImage, sizeof(uint8_t), iWidth*iHeight, fp);
memset(tpImage->vpImage, 0, iWidth * iHeight * sizeof(uint8_t));
fread(tpImage->vpImage, sizeof(uint8_t), iWidth * iHeight, fp);
break;
case CV_16U:
tpImage->vpImage = (uint16_t *)malloc(iWidth*iHeight * sizeof(uint16_t));
tpImage->vpImage = (uint16_t*)malloc(iWidth * iHeight * sizeof(uint16_t));
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, iWidth*iHeight * sizeof(uint16_t));
fread(tpImage->vpImage, sizeof(uint16_t), iWidth*iHeight, fp);
memset(tpImage->vpImage, 0, iWidth * iHeight * sizeof(uint16_t));
fread(tpImage->vpImage, sizeof(uint16_t), iWidth * iHeight, fp);
break;
default:
//不支持位深度
......@@ -124,7 +124,7 @@ int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth,
return FUNC_OK;
}
int eyemImageFromBitmap(void *vpScan0, int iWidth, int iHeight, int iDepth, int iChannels, EyemImage *tpImage)
int eyemImageFromBitmap(void* vpScan0, int iWidth, int iHeight, int iDepth, int iChannels, EyemImage* tpImage)
{
cv::Mat image = cv::Mat(iHeight, iWidth, MAKETYPE(iDepth, iChannels), vpScan0).clone();
//在这里重新创建
......@@ -136,9 +136,9 @@ int eyemImageFromBitmap(void *vpScan0, int iWidth, int iHeight, int iDepth, int
//图像信息
tpImage->iWidth = image.cols; tpImage->iHeight = image.rows; tpImage->iDepth = image.depth(); tpImage->iChannels = image.channels();
//内存尺寸
int _Size = tpImage->iWidth*tpImage->iHeight*tpImage->iChannels * sizeof(uint8_t);
int _Size = tpImage->iWidth * tpImage->iHeight * tpImage->iChannels * sizeof(uint8_t);
//分配内存
tpImage->vpImage = (uint8_t *)malloc(_Size);
tpImage->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
......@@ -147,80 +147,75 @@ int eyemImageFromBitmap(void *vpScan0, int iWidth, int iHeight, int iDepth, int
return FUNC_OK;
}
int eyemVideoCapture(const char *fileName, IntPtr *hObject, EyemImage **tpImages, int *ipNum)
int eyemVideoCapture(const char* fileName, IntPtr* hObject, EyemImage** tpImages, int* ipNum)
{
cv::VideoCapture cap;
cap.open(fileName);
if (!cap.isOpened())
return FUNC_CANNOT_CALC;
int totalFrmNum = (int)cap.get(cv::CAP_PROP_FRAME_COUNT);
std::vector<EyemImage> *pFrames = new std::vector<EyemImage>();
std::vector<EyemImage>* pFrames = new std::vector<EyemImage>();
cv::Mat nextImg;
while (true)
{
cap >> nextImg;
if (nextImg.empty())
break;
//图像信息
EyemImage tpImage;
tpImage.iWidth = nextImg.cols; tpImage.iHeight = nextImg.rows; tpImage.iDepth = nextImg.depth(); tpImage.iChannels = nextImg.channels();
//内存尺寸
int _Size = tpImage.iWidth*tpImage.iHeight*tpImage.iChannels;
int _Size = tpImage.iWidth * tpImage.iHeight * tpImage.iChannels;
//需要申请内存
switch (tpImage.iDepth)
{
case CV_8U:
_Size *= sizeof(uint8_t);
tpImage.vpImage = (uint8_t *)malloc(_Size);
tpImage.vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
break;
case CV_8S:
_Size *= sizeof(int8_t);
tpImage.vpImage = (int8_t *)malloc(_Size);
tpImage.vpImage = (int8_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
break;
case CV_16U:
_Size *= sizeof(uint16_t);
tpImage.vpImage = (uint16_t *)malloc(_Size);
tpImage.vpImage = (uint16_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
break;
case CV_16S:
_Size *= sizeof(int16_t);
tpImage.vpImage = (int16_t *)malloc(_Size);
tpImage.vpImage = (int16_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
break;
case CV_32S:
_Size *= sizeof(int32_t);
tpImage.vpImage = (int32_t *)malloc(_Size);
tpImage.vpImage = (int32_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
break;
case CV_32F:
_Size *= sizeof(float_t);
tpImage.vpImage = (float_t *)malloc(_Size);
tpImage.vpImage = (float_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
break;
case CV_64F:
_Size *= sizeof(double_t);
tpImage.vpImage = (double_t *)malloc(_Size);
tpImage.vpImage = (double_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
......@@ -238,7 +233,6 @@ int eyemVideoCapture(const char *fileName, IntPtr *hObject, EyemImage **tpImages
*tpImages = pFrames->data();
*ipNum = static_cast<int>(pFrames->size());
*hObject = reinterpret_cast<IntPtr>(pFrames);
return FUNC_OK;
}
......@@ -247,11 +241,11 @@ bool eyemVideoCaptureFree(IntPtr hObject)
if (NULL == hObject)
return true;
std::vector<EyemImage> *tpImages = reinterpret_cast<std::vector<EyemImage>*>(hObject);
std::vector<EyemImage>* tpImages = reinterpret_cast<std::vector<EyemImage>*>(hObject);
for (std::vector<EyemImage>::iterator it = tpImages->begin(); it != tpImages->end(); ++it)
{
EyemImage *tpImage = &(*it);
EyemImage* tpImage = &(*it);
tpImage->iWidth = tpImage->iHeight = tpImage->iDepth = tpImage->iChannels = 0;
free(tpImage->vpImage), tpImage->vpImage = NULL;
}
......@@ -263,7 +257,45 @@ bool eyemVideoCaptureFree(IntPtr hObject)
return true;
}
void eyemImageFree(EyemImage &tpImage)
void eyemNamedWindow(const char* winName)
{
cv::namedWindow(winName, cv::WINDOW_NORMAL);
}
void eyemDestroyAllWindows()
{
cv::destroyAllWindows();
}
void eyemImshow(const char* winName, EyemImage& tpImage)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat _src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
cv::imshow(winName, _src);
}
void eyemWaitkey()
{
cv::waitKey(0);
}
void eyemDrawHistogramImage(EyemImage tpImage, EyemImage* tpDstImg, int color[3], int mean_color[3], const bool isDrawGrid, const bool isDrawStats, const int normValue)
{
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty()) {
return;
}
cv::Mat src;
int incn = image.channels();
if (incn > 1) {
cv::cvtColor(image, src, cv::COLOR_BGR2GRAY);
}
else{
image.copyTo(src);
}
}
void eyemImageFree(EyemImage& tpImage)
{
tpImage.iWidth = tpImage.iHeight = tpImage.iDepth = tpImage.iChannels = 0;
//释放
......
......@@ -9,14 +9,14 @@
#ifndef FILEVERSION
#ifdef VQISDA
#define FILEVERSION "2.4.9.5 (Only Qisda)"
#define FILEVERSION "2.4.9.8 (Only Qisda)"
#else
#define FILEVERSION "2.4.9.5"
#define FILEVERSION "2.4.9.10"
#endif
#endif
#ifndef COPYRIGHT
#define COPYRIGHT "Copyright (C) 2020-2022 NeoTel. All Rights Reserved"
#define COPYRIGHT "Copyright (C) 2020-2025 NeoTel. All Rights Reserved"
#endif
#ifndef ORIGINALFILENAME
......@@ -177,7 +177,7 @@ enum {
// 图像信息
typedef struct {
void *vpImage; // 地址
void* vpImage; // 地址
int iWidth; // 图像内存 x 方向大小
int iHeight; // 图像内存 y 方向大小
int iDepth; // 图像位深度(参见说明)
......@@ -403,48 +403,48 @@ extern "C" {
double eyemMathCalcInnerProduct(int, double[], double[]);
void eyemMathCalcOuterProduct(double[], double[], double[]);
int eyemMathCalcAngle(int, double[], double[], double *);
int eyemMathCalcAngle(int, double[], double[], double*);
double eyemMathCalcNorm(int, double[]);
double eyemMathCalcArgument(double[]);
int eyemMathNormalization(int, double[]);
int eyemMathStat(int, double[], double *, double *, double *);
double eyemMathMedianI(int, int *);
double eyemMathMedianD(int, double *);
int eyemMathOtsuThreshold1d(int, double[], double *);
int eyemMathStat(int, double[], double*, double*, double*);
double eyemMathMedianI(int, int*);
double eyemMathMedianD(int, double*);
int eyemMathOtsuThreshold1d(int, double[], double*);
double eyemMathAreaTriangle(double, double, double, double, double, double);
double eyemMathSignAreaTriangle(double, double, double, double, double, double);
void eyemMathRotatePoint(double, double, double, double, double, double *, double *);
void eyemMathCreateTransParam(int, double, double, double, double, double *, double *, double *);
void eyemMathTransCoordOfPoint(double, double, double, double, double, double *, double *);
void eyemMathInvTransCoordOfPoint(double, double, double, double, double, double *, double *);
void eyemMathComposeCoord(double, double, double, double, double, double, double *, double *, double *);
void eyemMathRotatePoint(double, double, double, double, double, double*, double*);
void eyemMathCreateTransParam(int, double, double, double, double, double*, double*, double*);
void eyemMathTransCoordOfPoint(double, double, double, double, double, double*, double*);
void eyemMathInvTransCoordOfPoint(double, double, double, double, double, double*, double*);
void eyemMathComposeCoord(double, double, double, double, double, double, double*, double*, double*);
double eyemMathInvMatrixOfSyn3X3(double[][3], double[][3]);
void eyemMathInvCoord(double, double, double, double *, double *, double *);
void eyemMathInvCoord(double, double, double, double*, double*, double*);
double eyemMathGetDistFromPointToPoint(double, double, double, double);
double eyemMathGetDistFromPointToLine(double, double, double, double, double);
double eyemMathGetDistAndCrossPointFromPointToLine(double, double, double, double, double, double *, double *);
double eyemMathGetDistFromPointToCircle(double, double, double, double, double, double *, double *);
int eyemMathGetDistFromPointToEllipse(double, double, double, double, double, double, double, double *, double *, double *);
int eyemMathCrossPoint(double, double, double, double, double, double, double *, double *);
void eyemMathTransAbcToRq(double, double, double, double *, double *);
double eyemMathGetDistAndCrossPointFromPointToLine(double, double, double, double, double, double*, double*);
double eyemMathGetDistFromPointToCircle(double, double, double, double, double, double*, double*);
int eyemMathGetDistFromPointToEllipse(double, double, double, double, double, double, double, double*, double*, double*);
int eyemMathCrossPoint(double, double, double, double, double, double, double*, double*);
void eyemMathTransAbcToRq(double, double, double, double*, double*);
double eyemMathCrossAngle(double, double, double, double, double, double);
int eyemMathGetLineFrom2Points(double, double, double, double, double *, double *, double *);
void eyemMathGetOrthogonalLineFromLineAndPoint(double, double, double, double, double *, double *, double *);
int eyemMathGetLineFrom2Points(double, double, double, double, double*, double*, double*);
void eyemMathGetOrthogonalLineFromLineAndPoint(double, double, double, double, double*, double*, double*);
int eyemMathCheckAngle(double, double, double);
double eyemMathAddAngle(int, int, double, double);
double eyemMathPrimeAngle(int, int, double);
double eyemMathExtremumOfQuadraticCurves(double, double, double, double *);
double eyemMathExtremumOfQuadraticSurface(double, double, double, double, double, double, double *, double *);
double eyemMathExtremumOfQuadraticCurves(double, double, double, double*);
double eyemMathExtremumOfQuadraticSurface(double, double, double, double, double, double, double*, double*);
double eyemMathCrossCorrelation(int, double[], double[]);
int eyemMathAutoCorrelation(int, double[], int, double[]);
double eyemMathNormCorrelation(int, double[], double[]);
int eyemMathNormAutoCorrelation(int, double[], int, double[]);
int eyemMathSearchOf1DWithNormCorrelation(int, double[], int, double[], int *, double *);
int eyemMathSearchOf1DWithNormCorrelation(int, double[], int, double[], int*, double*);
int eyemMathQuadraticRoots(double[], double[]);
int eyemMathCubicRoots(double[], double[]);
int eyemMathQuarticRoots(double[], double[]);
double eyemMathHorner(int, double[], double);
void eyemMathTransCoord(double, double, double, double, double, double *, double *);
void eyemMathTransCoord(double, double, double, double, double, double*, double*);
#ifdef __cplusplus
}
......@@ -459,16 +459,19 @@ extern "C" {
#endif
// 函数接口
EXPORTS int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType, EyemImage *tpImage);
EXPORTS int eyemMatCopy(EyemImage &vpDst, EyemImage vpSrc);
EXPORTS int eyemMatAdd(EyemImage vpA, EyemImage vpB, EyemImage &vpC);
EXPORTS int eyemMatSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage &tpDstImg);
EXPORTS int eyemMatAbs(EyemImage &tpImage);
EXPORTS int eyemBitwiseNot(EyemImage &tpImage);
EXPORTS int eyemNormalize(EyemImage &tpImage);
EXPORTS int eyemDecompose(EyemImage tpImage, EyemImage *tpDstImgR, EyemImage *tpDstImgG, EyemImage *tpDstImgB);
EXPORTS int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, double beta, EyemImage &tpDstImg);
EXPORTS int eyemCvtImageColor(EyemImage tpImage, int iCCodes, EyemImage &tpDstImg);
EXPORTS int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char* ccSubType, EyemImage* tpImage);
EXPORTS int eyemMatCopy(EyemImage vpSrc, EyemImage& vpDst);
EXPORTS int eyemMatAdd(EyemImage vpA, EyemImage vpB, EyemImage& vpC);
EXPORTS int eyemMatSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage& tpDstImg);
EXPORTS int eyemMatAbs(EyemImage& tpImage);
EXPORTS int eyemBitwiseNot(EyemImage& tpImage);
EXPORTS int eyemNormalize(EyemImage& tpImage);
EXPORTS int eyemDecompose(EyemImage tpImage, EyemImage* tpDstImgR, EyemImage* tpDstImgG, EyemImage* tpDstImgB);
EXPORTS int eyemCvtImageType(EyemImage tpImage, const char* ccSubType, double alpha, double beta, EyemImage& tpDstImg);
EXPORTS int eyemCvtImageColor(EyemImage tpImage, int iCCodes, EyemImage& tpDstImg);
EXPORTS int eyemWarpShiftSubpix(EyemImage tpImage, double dShiftX, double dShiftY, EyemImage* tpDstImg, int iInterMethod);
EXPORTS int eyemCopyRegion(EyemImage& tpImage, EyemRect tpRoi, EyemImage* tpDstImg);
EXPORTS int eyemCountNonZero(EyemImage& tpImage);
#ifdef __cplusplus
}
......@@ -509,14 +512,14 @@ extern "C" {
#endif
// 函数接口
EXPORTS int eyemFitLine(int iPtnNum, EyemOcsDXY *taPoint, int iNumToIgnore, EyemOcsDABC &tpLine);
EXPORTS int eyemRobustFitLine(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, double dRobustCoef, EyemOcsDABC &tpLine);
EXPORTS int eyemFitLineRANSAC(int iPtnNum, EyemOcsDXY *taPoint, double dClippingFactor, EyemOcsDABC &tpLine);
EXPORTS int eyemFitCircle(int iPtnNum, EyemOcsDXY *taPoint, int iNumToIgnore, double &dRMS, EyemOcsDXYR &tpCircle);
EXPORTS int eyemRobustFitCircle(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, double dRobustCoef, EyemOcsDXYR &tpCircle);
EXPORTS int eyemFitRTMatrix(int iPtnNum, EyemOcsDXY *taPointA, EyemOcsDXY *taPointB, EyemRigidMatrix &dpResult);
EXPORTS int eyemRobustFitPlane(int iPtnNum, EyemOcsDXYZ *taPoint, int iCalcMode, double dRobustCoef, EyemOcsDABCD &tpPlane);
EXPORTS int eyemRobustFitEllipse(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, double dRobustCoef, EyemOcsDXYLSQ &tpEllipse);
EXPORTS int eyemFitLine(int iPtnNum, EyemOcsDXY* taPoint, int iNumToIgnore, EyemOcsDABC& tpLine);
EXPORTS int eyemRobustFitLine(int iPtnNum, EyemOcsDXY* taPoint, int iCalcMode, double dRobustCoef, EyemOcsDABC& tpLine);
EXPORTS int eyemFitLineRANSAC(int iPtnNum, EyemOcsDXY* taPoint, double dClippingFactor, EyemOcsDABC& tpLine);
EXPORTS int eyemFitCircle(int iPtnNum, EyemOcsDXY* taPoint, int iNumToIgnore, double& dRMS, EyemOcsDXYR& tpCircle);
EXPORTS int eyemRobustFitCircle(int iPtnNum, EyemOcsDXY* taPoint, int iCalcMode, double dRobustCoef, EyemOcsDXYR& tpCircle);
EXPORTS int eyemFitRTMatrix(int iPtnNum, bool bFullAffine, EyemOcsDXY* taPointA, EyemOcsDXY* taPointB, EyemRigidMatrix& dpResult);
EXPORTS int eyemRobustFitPlane(int iPtnNum, EyemOcsDXYZ* taPoint, int iCalcMode, double dRobustCoef, EyemOcsDABCD& tpPlane);
EXPORTS int eyemRobustFitEllipse(int iPtnNum, EyemOcsDXY* taPoint, int iCalcMode, double dRobustCoef, EyemOcsDXYLSQ& tpEllipse);
#ifdef __cplusplus
}
......@@ -531,23 +534,23 @@ extern "C" {
#endif
// 函数接口
EXPORTS void eyemClp2dDistanceTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, double &tpDist);
EXPORTS void eyemClp2dCenterTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDXY &tpCenter);
EXPORTS int eyemClp2dLineTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDABC &tpLine);
EXPORTS int eyemClp2dMidperpendicularTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDABC &tpLine);
EXPORTS int eyemClp2dVerticalLinePointAndLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, EyemOcsDABC &tpVertical);
EXPORTS void eyemClp2dLinePointAndSlope(EyemOcsDXY tpPoint, double dSlope, EyemOcsDABC &tpLine);
EXPORTS int eyemClp2dIntersectionTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, EyemOcsDXY &tpPoint);
EXPORTS int eyemClp2dIntersectionLineSegment(EyemOcsDABC tpLine, EyemOcsDXY tpPtSt, EyemOcsDXY tpPtEd, int *ipStatus, EyemOcsDXY &tpPoint);
EXPORTS int eyemClp2dIntersectionOfTwoSegments(EyemOcsDXY tpPt1St, EyemOcsDXY tpPt1Ed, EyemOcsDXY tpPt2St, EyemOcsDXY tpPt2Ed, int *ipStatus, EyemOcsDXY &tpPoint);
EXPORTS int eyemClp2dAngleTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, double &dpAngle);
EXPORTS int eyemClp2dCenterLineOfTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, EyemOcsDABC &tpLineC);
EXPORTS int eyemClp2dDistancePointToLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, double &dpDist);
EXPORTS int eyemClp2dTranslationOfLine(EyemOcsDABC tpSrcL, EyemOcsDXY tpTrans, EyemOcsDABC &tpDstL);
EXPORTS void eyemClp2dAreaTriangle(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDXY tpPoint3, double &dpArea);
EXPORTS int eyemClp2dCircleThreePoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDXY tpPoint3, EyemOcsDXYR &tpCircle);
EXPORTS int eyemClp2dIntersectionLineAndCircle(EyemOcsDABC tpLine, EyemOcsDXYR tpCircle, EyemOcsDXY &tpPoint1, EyemOcsDXY &tpPoint2);
EXPORTS int eyemClp2dTangentPointToCircle(EyemOcsDXY tpPoint, EyemOcsDXYR tpCircle, EyemOcsDABC &tpTangent1, EyemOcsDXY &tpContact1, EyemOcsDABC &tpTangent2, EyemOcsDXY &tpContact2);
EXPORTS void eyemClp2dDistanceTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, double& tpDist);
EXPORTS void eyemClp2dCenterTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDXY& tpCenter);
EXPORTS int eyemClp2dLineTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDABC& tpLine);
EXPORTS int eyemClp2dMidperpendicularTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDABC& tpLine);
EXPORTS int eyemClp2dVerticalLinePointAndLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, EyemOcsDABC& tpVertical);
EXPORTS void eyemClp2dLinePointAndSlope(EyemOcsDXY tpPoint, double dSlope, EyemOcsDABC& tpLine);
EXPORTS int eyemClp2dIntersectionTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, EyemOcsDXY& tpPoint);
EXPORTS int eyemClp2dIntersectionLineSegment(EyemOcsDABC tpLine, EyemOcsDXY tpPtSt, EyemOcsDXY tpPtEd, int* ipStatus, EyemOcsDXY& tpPoint);
EXPORTS int eyemClp2dIntersectionOfTwoSegments(EyemOcsDXY tpPt1St, EyemOcsDXY tpPt1Ed, EyemOcsDXY tpPt2St, EyemOcsDXY tpPt2Ed, int* ipStatus, EyemOcsDXY& tpPoint);
EXPORTS int eyemClp2dAngleTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, double& dpAngle);
EXPORTS int eyemClp2dCenterLineOfTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, EyemOcsDABC& tpLineC);
EXPORTS int eyemClp2dDistancePointToLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, double& dpDist);
EXPORTS int eyemClp2dTranslationOfLine(EyemOcsDABC tpSrcL, EyemOcsDXY tpTrans, EyemOcsDABC& tpDstL);
EXPORTS void eyemClp2dAreaTriangle(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDXY tpPoint3, double& dpArea);
EXPORTS int eyemClp2dCircleThreePoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDXY tpPoint3, EyemOcsDXYR& tpCircle);
EXPORTS int eyemClp2dIntersectionLineAndCircle(EyemOcsDABC tpLine, EyemOcsDXYR tpCircle, EyemOcsDXY& tpPoint1, EyemOcsDXY& tpPoint2);
EXPORTS int eyemClp2dTangentPointToCircle(EyemOcsDXY tpPoint, EyemOcsDXYR tpCircle, EyemOcsDABC& tpTangent1, EyemOcsDXY& tpContact1, EyemOcsDABC& tpTangent2, EyemOcsDXY& tpContact2);
#ifdef __cplusplus
}
......@@ -583,14 +586,14 @@ extern "C" {
// 函数接口
int eyemCgSortByArgument(int n, EyemOcsDXY taSrcPt[], EyemOcsDXY taDstPt[]);
int eyemCgConvexHull(int, EyemOcsDXY[], int *, EyemOcsDXY[]);
int eyemCgSmallestEnclosingCircle(int, EyemOcsDXY[], EyemOcsDXY *, double *);
int eyemCgIntersectionOfTwoSegments(EyemOcsDXY *, EyemOcsDXY *, EyemOcsDXY *, EyemOcsDXY *, int *, EyemOcsDXY *);
int eyemCgPointInConvexPolygon(int, EyemOcsDXY[], EyemOcsDXY *, int *);
int eyemCgIntersectionLineAndConvexPolygon(int, EyemOcsDXY[], EyemOcsDABC *, EyemOcsDXY[]);
int eyemCgIntersectionSegmentAndConvexPolygon(int, EyemOcsDXY[], EyemOcsDXY *, EyemOcsDXY *, EyemOcsDXY[]);
int eyemCgPointInPolygon(int, EyemOcsDXY[], EyemOcsDXY *, int *);
int eyemCgAreaOfPolygon(int, EyemOcsDXY[], double *);
int eyemCgConvexHull(int, EyemOcsDXY[], int*, EyemOcsDXY[]);
int eyemCgSmallestEnclosingCircle(int, EyemOcsDXY[], EyemOcsDXY*, double*);
int eyemCgIntersectionOfTwoSegments(EyemOcsDXY*, EyemOcsDXY*, EyemOcsDXY*, EyemOcsDXY*, int*, EyemOcsDXY*);
int eyemCgPointInConvexPolygon(int, EyemOcsDXY[], EyemOcsDXY*, int*);
int eyemCgIntersectionLineAndConvexPolygon(int, EyemOcsDXY[], EyemOcsDABC*, EyemOcsDXY[]);
int eyemCgIntersectionSegmentAndConvexPolygon(int, EyemOcsDXY[], EyemOcsDXY*, EyemOcsDXY*, EyemOcsDXY[]);
int eyemCgPointInPolygon(int, EyemOcsDXY[], EyemOcsDXY*, int*);
int eyemCgAreaOfPolygon(int, EyemOcsDXY[], double*);
#ifdef __cplusplus
}
......@@ -675,16 +678,16 @@ extern "C" {
#endif
// 函数接口
EXPORTS int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double dMaxVal, EyemImage *tpDstImg);
EXPORTS int eyemBinThresholdC(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpDstImg);
EXPORTS int eyemBinAutoThreshold(EyemImage tpSrcImg, double dSigma, int iLightDark, int binMethod, EyemImage *tpDstImg);
EXPORTS int eyemBinNiBlack(EyemImage tpSrcImg, int iType, int iWinSize, double dK, int binarizationMethod, double dR, EyemImage *tpDstImg);
EXPORTS int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpPreImg, double dOffset, int iType, EyemImage *tpDstImg);
EXPORTS int eyemBinDilation(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg);
EXPORTS int eyemBinErosion(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg);
EXPORTS int eyemBinOpening(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg);
EXPORTS int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg);
EXPORTS int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, EyemBinBlob **tpResult, int *ipNum, EyemImage *tpDstImg);
EXPORTS int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double dMaxVal, EyemImage* tpDstImg);
EXPORTS int eyemBinThresholdC(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage* tpDstImg);
EXPORTS int eyemBinAutoThreshold(EyemImage tpSrcImg, double dSigma, int iLightDark, int binMethod, EyemImage* tpDstImg);
EXPORTS int eyemBinNiBlack(EyemImage tpSrcImg, int iType, int iWinSize, double dK, int binarizationMethod, double dR, EyemImage* tpDstImg);
EXPORTS int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpPreImg, double dOffset, int iType, EyemImage* tpDstImg);
EXPORTS int eyemBinDilation(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage* tpDstImg);
EXPORTS int eyemBinErosion(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage* tpDstImg);
EXPORTS int eyemBinOpening(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage* tpDstImg);
EXPORTS int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage* tpDstImg);
EXPORTS int eyemBinBlob(EyemImage tpImage, IntPtr* hObject, EyemBlobParams tpParams, EyemBinBlob** tpResult, int* ipNum, EyemImage* tpDstImg);
EXPORTS bool eyemBinFree(IntPtr hObject);
#ifdef __cplusplus
......@@ -702,10 +705,10 @@ extern "C" {
#endif
// 函数接口
EXPORTS int eyemEdge1dGenMeasureRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, const char *ccSubType, int iTransition, double dSigma, double dAmpThresh, IntPtr *hObject);
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 eyemEdge1dGenMeasureRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, const char* ccSubType, int iTransition, double dSigma, double dAmpThresh, IntPtr* hObject);
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 eyemPolarTrans(EyemImage tpImage, EyemOcsDXY tpCenter, int iRadius, int iSapWidth);
EXPORTS bool eyemEdge1dGenFree(IntPtr hObject);
......@@ -722,10 +725,10 @@ extern "C" {
#endif
// 函数接口
EXPORTS int eyemEdgesPixel(EyemImage tpImage, double dThreshold, IntPtr *hObject, int *ipNum, EyemOcsDXY **hResults);
EXPORTS int eyemEdgesSubpixel(EyemImage tpImage, IntPtr *hObject, EyemOcsDXY **tpEdges, int iFilter, int iLow, int iHigh);
EXPORTS int eyemSkeleton(EyemImage tpImage, EyemImage &skeleton);
EXPORTS int eyemSobelAmp(EyemImage tpImage, EyemImage &ImaAmp);
EXPORTS int eyemEdgesPixel(EyemImage tpImage, double dThreshold, IntPtr* hObject, int* ipNum, EyemOcsDXY** hResults);
EXPORTS int eyemEdgesSubpixel(EyemImage tpImage, IntPtr* hObject, EyemOcsDXY** tpEdges, int iFilter, int iLow, int iHigh);
EXPORTS int eyemSkeleton(EyemImage tpImage, EyemImage& skeleton);
EXPORTS int eyemSobelAmp(EyemImage tpImage, EyemImage& ImaAmp);
EXPORTS int eyemAutoCanny(EyemImage tpImage, float dSigma = 0.33);
#ifdef __cplusplus
......@@ -753,7 +756,7 @@ extern "C" {
EXPORTS int eyemFindShapeModel(EyemImage tpImage, int iNumLevels, double dAngleStart, double dAngleExtent, double dAngleStep, double dMinContrast, double dContrast, double dGreediness, double dMinScore, bool bOptimization = true);
EXPORTS int eyemMakeNCCModel(EyemImage tpImage, int iMinReduceArea);
EXPORTS int eyemFindNCCModel(EyemImage tpImage, double dToleranceAngle, int iNumMatches, double dMaxOverlap, double dScore, EyemTargetMatch *tpResults);
EXPORTS int eyemFindNCCModel(EyemImage tpImage, double dToleranceAngle, int iNumMatches, double dMaxOverlap, double dScore, bool bDrawResult, EyemTargetMatch* tpResults, EyemImage* tpDstImg);
#ifdef __cplusplus
}
......@@ -780,9 +783,9 @@ extern "C" {
#endif
// 函数接口
int eyemMatchBasic(int, EyemOcsDXY[], EyemOcsDXY[], EyemOcsDXYQ *, int, double, EyemOcsDXYQS *);
int eyemMatchDelta(EyemOcsDXYQ *, EyemOcsDXYQS *, double *, double *, double *, double *);
int eyemMatchPoints(int, EyemOcsDXY[], EyemOcsDXY[], EyemOcsDXYQ *, EyemOcsDXYQS *, EyemOcsDXY[], double[]);
int eyemMatchBasic(int, EyemOcsDXY[], EyemOcsDXY[], EyemOcsDXYQ*, int, double, EyemOcsDXYQS*);
int eyemMatchDelta(EyemOcsDXYQ*, EyemOcsDXYQS*, double*, double*, double*, double*);
int eyemMatchPoints(int, EyemOcsDXY[], EyemOcsDXY[], EyemOcsDXYQ*, EyemOcsDXYQS*, EyemOcsDXY[], double[]);
#ifdef __cplusplus
}
......@@ -796,8 +799,8 @@ extern "C" {
// 模式数据
typedef struct {
int iPtnRefN; // 图案参考点数
EyemOcsDXY *tpObjPt; // 阵列参考点的实际坐标(単位:mm)
EyemOcsDXY *tpImgPt; // 图案参考点的图像坐标(単位:像素)
EyemOcsDXY* tpObjPt; // 阵列参考点的实际坐标(単位:mm)
EyemOcsDXY* tpImgPt; // 图案参考点的图像坐标(単位:像素)
} EyemCalibPtn;
......@@ -830,12 +833,12 @@ extern "C" {
#endif
// 函数接口
int eyemCalibCameraCalibrate(int, EyemCalibPtn[], double, EyemCalibInt *, EyemCalibExt[], double *, int);
int eyemCalibCalcHomography(int, void *, void *, double, void *);
int eyemCalibCameraCalibrate(int, EyemCalibPtn[], double, EyemCalibInt*, EyemCalibExt[], double*, int);
int eyemCalibCalcHomography(int, void*, void*, double, void*);
int eyemCalibRodrigues(int, double[3], double[3][3]);
int eyemCalibUnDistortPoint(EyemCalibInt *, double, double, double *, double *);
int eyemCalibUnDistortMat(EyemCalibInt *, double, double, double *, double *);
int eyemCalibChange3Dto2D(EyemOcsDXYZ *, EyemCalibInt *, EyemCalibExt *, EyemOcsDXY *, int);
int eyemCalibUnDistortPoint(EyemCalibInt*, double, double, double*, double*);
int eyemCalibUnDistortMat(EyemCalibInt*, double, double, double*, double*);
int eyemCalibChange3Dto2D(EyemOcsDXYZ*, EyemCalibInt*, EyemCalibExt*, EyemOcsDXY*, int);
#ifdef __cplusplus
}
......@@ -850,10 +853,10 @@ extern "C" {
#endif
// 函数接口
EXPORTS int eyemSmoothMean(EyemImage tpImage, int kSizew, int kSizeh, EyemImage *tpDstImg);
EXPORTS int eyemSmoothGaussian(EyemImage tpImage, int kSizew, int kSizeh, double dSigmaX, double dSigmaY, EyemImage *tpDstImg);
EXPORTS int eyemSmoothMedian(EyemImage tpImage, int kSize, EyemImage *tpDstImg);
EXPORTS int eyemShockFilter(EyemImage tpImage, int kSize, double dSigma, double dBlend, const int iIter, EyemImage *tpDstImg);
EXPORTS int eyemSmoothMean(EyemImage tpImage, int kSizew, int kSizeh, EyemImage* tpDstImg);
EXPORTS int eyemSmoothGaussian(EyemImage tpImage, int kSizew, int kSizeh, double dSigmaX, double dSigmaY, EyemImage* tpDstImg);
EXPORTS int eyemSmoothMedian(EyemImage tpImage, int kSize, EyemImage* tpDstImg);
EXPORTS int eyemShockFilter(EyemImage tpImage, int kSize, double dSigma, double dBlend, const int iIter, EyemImage* tpDstImg);
EXPORTS int eyemNonLocalMeansFilter(EyemImage tpImage, int iCMPSize, int iSearchSize, double dH, double dSigma);
#ifdef __cplusplus
......@@ -869,14 +872,18 @@ extern "C" {
#endif
// 函数接口
EXPORTS void* eyemMallocMemBlock(int cb);
EXPORTS void* eyemMallocMemBlock(int cb);
EXPORTS void eyemFreeMemBlock(void* block);
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 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);
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 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);
EXPORTS bool eyemVideoCaptureFree(IntPtr hObject);
EXPORTS void eyemImageFree(EyemImage &ipImage);
EXPORTS void eyemImageFree(EyemImage& ipImage);
EXPORTS void eyemNamedWindow(const char* winName);
EXPORTS void eyemImshow(const char* winName, EyemImage& tpImage);
EXPORTS void eyemWaitkey();
EXPORTS void eyemDrawHistogramImage(EyemImage tpImage, EyemImage* tpDstImg, int color[3], int mean_color[3], const bool isDrawGrid, const bool isDrawStats, const int normValue);
#ifdef __cplusplus
}
......@@ -896,13 +903,13 @@ extern "C" {
#endif
// 函数接口
EXPORTS int eyemInitNNDetector(const char *detectorConfigPath, const char *detectorModelPath, int iNetSizew, int iNetSizeh);
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 eyemInitClassifier(const char *classifierConfigPath, const char *classifierModelPath, int ntype);
EXPORTS int eyemNNDetector(EyemImage tpImage, int* ipNum, BboxContainer& 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);
EXPORTS int eyemExtractWithONNX(EyemImage tpImage, float *fFeatures);
EXPORTS int eyemInitONNXModel(const char* extractorModelPath);
EXPORTS int eyemExtractWithONNX(EyemImage tpImage, float* fFeatures);
#ifdef __cplusplus
......@@ -919,57 +926,57 @@ typedef struct {
double dAngle; // 角度
int iCenterX; // y坐标
int iCenterY; // y坐标
char* lpszType; // 码类型
char* lpszText; // 码内容
char* lpszType; // 码类型
char* lpszText; // 码内容
} EyemBarCode;
typedef struct {
void *vpImage; // 地址
void* vpImage; // 地址
int iXs; // 图像X坐标
int iYs; // 图像Y坐标
int iWidth; // 图像内存X方向大小
int iHeight; // 图像内存Y方向大小
double dMatchDeg; // 匹配度
char* lpszName; // 名称
char* lpszName; // 名称
} EyemModelID;
#ifdef __cplusplus
extern "C" {
#endif
EXPORTS int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char *ccFileName, const char *ccCodeType, IntPtr *hObject, EyemBarCode **tpResult, int *ipNum, bool bUseNiBlack, int iBlockSize, const int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown = 0.5, double dToleErr = 0.5, double dMinorStep = 1.0);
EXPORTS int eyemDetectAndDecodeUseNN(EyemImage tpImage, EyemRect tpRoi, IntPtr *hObject, EyemBarCode **hResults, int *ipNum, EyemImage *tpDstImg);
EXPORTS int eyemInitNNDataCodeModel(const char *detectorConfigPath, const char *detectorModelPath, const char *superResolutionConfigPath, const char *superResolutionModelPath);
EXPORTS int eyemDetectAndDecodeBarcodeUseNN(EyemImage tpImage, EyemRect tpRoi, IntPtr *hObject, EyemBarCode **hResults, int *ipNum, EyemImage *tpDstImg);
EXPORTS int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char* ccFileName, const char* ccCodeType, IntPtr* hObject, EyemBarCode** tpResult, int* ipNum, bool bUseNiBlack, int iBlockSize, const int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown = 0.5, double dToleErr = 0.5, double dMinorStep = 1.0);
EXPORTS int eyemDetectAndDecodeUseNN(EyemImage tpImage, EyemRect tpRoi, IntPtr* hObject, EyemBarCode** hResults, int* ipNum, EyemImage* tpDstImg);
EXPORTS int eyemInitNNDataCodeModel(const char* detectorConfigPath, const char* detectorModelPath, const char* superResolutionConfigPath, const char* superResolutionModelPath);
EXPORTS int eyemDetectAndDecodeBarcodeUseNN(EyemImage tpImage, EyemRect tpRoi, IntPtr* hObject, EyemBarCode** hResults, int* ipNum, EyemImage* tpDstImg);
EXPORTS bool eyemDetectAndDecodeFree(IntPtr hObject);
EXPORTS int eyemInitCounter(const char *extractorModelPath);
EXPORTS int eyemCountObject(EyemImage tpImage, EyemRect tpRoi, const char *fileName, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char *fileName, const char * ccSubType, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, const char *ccTplName, IntPtr hModelID, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularPartsMultiopt(EyemImage tpImage, EyemRect tpRoi, int iOptions[4], int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectUseNN(EyemImage tpImage, EyemRect tpRoi, const char *fileName, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemAchvMatchMat(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg);
EXPORTS int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg);
EXPORTS int eyemCreateTemplateModel(EyemImage tpImage, EyemRect tpRoi, double dMinScore, const char *ccTplName);
EXPORTS int eyemMatchTemplateModel(EyemImage tpImage, IntPtr hModelID, char **lpszTplName);
EXPORTS int eyemInitModel(const char *ccTplName, IntPtr *hModelID);
EXPORTS int eyemAchvModelByName(const char *ccTplName, IntPtr hModelID, EyemModelID &tpModelID);
EXPORTS int eyemInsertModel(IntPtr hModelID, const char *ccTplName);
EXPORTS int eyemRemoveModelByName(IntPtr hModelID, const char *ccTplName);
EXPORTS int eyemReleaseModel(IntPtr &hModelID);
EXPORTS int eyemTrackFeature(EyemImage tpImage, EyemImage tpMask, EyemRect tpRoi, EyemRect *tpRois, int iRoiNum, EyemHSVModel tpHSVModel, int *ipResults, EyemImage *tpDstImg);
EXPORTS int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum);
EXPORTS int eyemMarkerTracing(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemOcsFXYR *tpCircle, EyemImage *tpDstImg, bool bHighAccuracy = false);
EXPORTS int eyemDetectCircleUseHough(EyemImage tpImage, EyemRect tpRoi, EyemRect limRoi, EyemOcsDXYR *tpCircle, EyemImage *tpDstImg, double dp, double dMinDist, double dParam1, double dParam2, double dMinRadius, double dMaxRadius, int iMethod = 3, bool useValLimit = false);
EXPORTS int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, double dThreshold, int iNumToIgnore, EyemOcsFXYR *tpCircle, EyemImage *tpDstImg);
EXPORTS int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg);
EXPORTS int eyemInitCounter(const char* extractorModelPath);
EXPORTS int eyemCountObject(EyemImage tpImage, EyemRect tpRoi, const char* fileName, int* ipReelNum, EyemImage* tpDstImg);
EXPORTS int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char* fileName, int* ipReelNum, EyemImage* tpDstImg);
EXPORTS int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char* fileName, const char* ccSubType, int* ipReelNum, EyemImage* tpDstImg);
EXPORTS int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, const char* fileName, const char* ccTplName, IntPtr hModelID, int* ipReelNum, EyemImage* tpDstImg);
EXPORTS int eyemCountObjectIrregularPartsMultiopt(EyemImage tpImage, EyemRect tpRoi, int iOptions[4], int* ipReelNum, EyemImage* tpDstImg);
EXPORTS int eyemCountObjectUseNN(EyemImage tpImage, EyemRect tpRoi, const char* fileName, int* ipReelNum, EyemImage* tpDstImg);
EXPORTS int eyemAchvMatchMat(EyemImage tpImage, EyemRect tpRoi, EyemImage* tpDstImg);
EXPORTS int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage* tpDstImg);
EXPORTS int eyemCreateTemplateModel(EyemImage tpImage, EyemRect tpRoi, double dMinScore, const char* ccTplName);
EXPORTS int eyemMatchTemplateModel(EyemImage tpImage, IntPtr hModelID, char** lpszTplName);
EXPORTS int eyemInitModel(const char* ccTplName, IntPtr* hModelID);
EXPORTS int eyemAchvModelByName(const char* ccTplName, IntPtr hModelID, EyemModelID& tpModelID);
EXPORTS int eyemInsertModel(IntPtr hModelID, const char* ccTplName);
EXPORTS int eyemRemoveModelByName(IntPtr hModelID, const char* ccTplName);
EXPORTS int eyemReleaseModel(IntPtr& hModelID);
EXPORTS int eyemTrackFeature(EyemImage tpImage, EyemImage tpMask, EyemRect tpRoi, EyemRect* tpRois, int iRoiNum, EyemHSVModel tpHSVModel, int* ipResults, EyemImage* tpDstImg);
EXPORTS int eyemAOIPreprocessingForTSAV(EyemImage tpImage, EyemRect tpRoi, EyemImage* tpDstImg);
EXPORTS int eyemMarkerTracing(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemOcsFXYR* tpCircle, EyemImage* tpDstImg, bool bHighAccuracy = false);
EXPORTS int eyemDetectCircleUseHough(EyemImage tpImage, EyemRect tpRoi, EyemRect limRoi, EyemOcsDXYR* tpCircle, EyemImage* tpDstImg, double dp, double dMinDist, double dParam1, double dParam2, double dMinRadius, double dMaxRadius, int iMethod = 3, bool useValLimit = false);
EXPORTS int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char* funcName, double dThreshold, int iNumToIgnore, EyemOcsFXYR* tpCircle, EyemImage* tpDstImg);
EXPORTS int eyemLibImpl(EyemImage tpImage, EyemImage* tpDstImg);
EXPORTS int eyemDrawLine(EyemImage tpImage, EyemOcsDABC tpLine);
EXPORTS int eyemDrawCircle(EyemImage tpImage, EyemOcsDXYR tpCircle);
EXPORTS int eyemDrawRectangle(EyemImage tpImag, EyemRect tpRect);
EXPORTS int eyemTrainImageSampler(EyemImage tpImage, int iSize, const char *ccClassName, const char *ccToPath, EyemImage *tpMatchImg, EyemImage *tpDstImg);
EXPORTS int eyemTrainImageSampler(EyemImage tpImage, int iSize, const char* ccClassName, const char* ccToPath, EyemImage* tpMatchImg, EyemImage* tpDstImg);
EXPORTS int eyemAffineTransform(EyemImage tpImage, double tAngle, EyemOcsDXY tpCenter, EyemImage* tpDstImg);
EXPORTS int eyemSIFTBasedMatch(EyemImage tpImage, EyemImage tpTargetImg, EyemImage tpMask, double dMinScore, EyemImage* tpDstImg);
EXPORTS int eyemAchvMaskImage(EyemImage tpImage, EyemImage *tpDstImg, EyemImage *tpPrevImg);
EXPORTS int eyemAchvMaskImage(EyemImage tpImage, EyemImage* tpDstImg, EyemImage* tpPrevImg);
EXPORTS int eyemSplitMask(EyemImage tpImage, EyemImage tpMask, const char* ccToPath, const char* ccClassName);
......@@ -987,13 +994,13 @@ extern "C" __declspec(dllexport) void setProcessLevel(double pl);
extern "C" __declspec(dllexport) void setFineTuning(double ft);
// 加载图像到内存
extern "C" __declspec(dllexport) void loadImage2Mem(const char *key, EyemImage tpImage);
extern "C" __declspec(dllexport) void loadImage2Mem(const char* key, EyemImage tpImage);
// 计算余弦相似度
extern "C" __declspec(dllexport) float calcSimilarity(float *lhs, float *rhs);
extern "C" __declspec(dllexport) float calcSimilarity(float* lhs, float* rhs);
// 日志回调定义
typedef void(__stdcall*TCallback)(const char* msg);
typedef void(__stdcall* TCallback)(const char* msg);
class Logger
{
......
此文件类型无法预览
......@@ -46,7 +46,7 @@
<ProjectGuid>{33D5F550-C799-4B05-8E14-ACA390DF5442}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>eyemLib</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
......@@ -85,33 +85,33 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_V455|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_V420Qisda|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseV455|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
......@@ -159,14 +159,14 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Debug;$(LibraryPath)</LibraryPath>
<IncludePath>D:\3rdparty\opencv420\build\include;D:\3rdparty\opencv420\build\include\opencv2;D:\3rdparty\tbb2017_20170604oss\include;D:\3rdparty\zxing-cpp-master\core\src;D:\3rdparty\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\3rdparty\opencv420\build\x64\vc14\lib;D:\3rdparty\tbb2017_20170604oss\lib\intel64\vc14;D:\3rdparty\zxing-cpp-master\build\Debug;$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_V455|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>D:\opencv455\build\include;D:\opencv455\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv455\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Debug;$(LibraryPath)</LibraryPath>
<IncludePath>D:\3rdparty\opencv455\build\include;D:\3rdparty\opencv455\build\include\opencv2;D:\3rdparty\tbb2017_20170604oss\include;D:\3rdparty\zxing-cpp-master\core\src;D:\3rdparty\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\3rdparty\opencv455\build\x64\vc15\lib;D:\3rdparty\tbb2017_20170604oss\lib\intel64\vc14;D:\3rdparty\zxing-cpp-master\build\Debug;$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......@@ -180,20 +180,20 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Release;$(LibraryPath)</LibraryPath>
<IncludePath>D:\3rdparty\opencv420\build\include;D:\3rdparty\opencv420\build\include\opencv2;D:\3rdparty\tbb2017_20170604oss\include;D:\3rdparty\zxing-cpp-master\core\src;D:\3rdparty\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\3rdparty\opencv420\build\x64\vc14\lib;D:\3rdparty\tbb2017_20170604oss\lib\intel64\vc14;D:\3rdparty\zxing-cpp-master\build\Release;$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_V420Qisda|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Release;$(LibraryPath)</LibraryPath>
<IncludePath>D:\3rdparty\opencv420\build\include;D:\3rdparty\opencv420\build\include\opencv2;D:\3rdparty\tbb2017_20170604oss\include;D:\3rdparty\zxing-cpp-master\core\src;D:\3rdparty\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\3rdparty\opencv420\build\x64\vc14\lib;D:\3rdparty\tbb2017_20170604oss\lib\intel64\vc14;D:\3rdparty\zxing-cpp-master\build\Release;$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseV455|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>D:\opencv455\build\include;D:\opencv455\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv455\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Release;$(LibraryPath)</LibraryPath>
<IncludePath>D:\3rdparty\opencv455\build\include;D:\3rdparty\opencv455\build\include\opencv2;D:\3rdparty\tbb2017_20170604oss\include;D:\3rdparty\zxing-cpp-master\core\src;D:\3rdparty\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\3rdparty\opencv455\build\x64\vc14\lib;D:\3rdparty\tbb2017_20170604oss\lib\intel64\vc14;D:\3rdparty\zxing-cpp-master\build\Release;$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
......@@ -212,6 +212,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>eyemLib.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug_V455|Win32'">
......@@ -230,6 +231,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>eyemLib.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
......@@ -247,6 +249,7 @@
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing-debug.lib;libdecoded.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>eyemLib.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug_V455|x64'">
......@@ -264,6 +267,7 @@
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing-debug.lib;libdecoded.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>eyemLib.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......@@ -282,6 +286,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>eyemLib.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_V420Qisda|Win32'">
......@@ -300,6 +305,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>eyemLib.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseV455|Win32'">
......@@ -318,6 +324,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>eyemLib.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
......@@ -342,6 +349,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing.lib;libdecode.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>eyemLib.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_V420Qisda|x64'">
......@@ -366,6 +374,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing.lib;libdecode.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>eyemLib.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseV455|x64'">
......@@ -390,6 +399,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing.lib;libdecode.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>eyemLib.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
......@@ -448,6 +458,9 @@
<ItemGroup>
<ResourceCompile Include="eyemLib.rc" />
</ItemGroup>
<ItemGroup>
<None Include="eyemLib.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
......
......@@ -170,4 +170,9 @@
<Filter>资源文件</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="eyemLib.def">
<Filter>源文件</Filter>
</None>
</ItemGroup>
</Project>
\ No newline at end of file
#include "eyemMat.h"
static void _free(EyemImage &tpImage)
static void _free(EyemImage& tpImage)
{
tpImage.iWidth = tpImage.iHeight = tpImage.iDepth = tpImage.iChannels = 0;
//释放
......@@ -8,7 +8,7 @@ static void _free(EyemImage &tpImage)
tpImage.vpImage = NULL;
}
int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType, EyemImage *tpImage)
int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char* ccSubType, EyemImage* tpImage)
{
CV_Assert(iWidth != 0 && iHeight != 0 && (iChannels == 1 || iChannels == 3 || iChannels == 4) && strcmp(ccSubType, "") != 0);
......@@ -19,12 +19,12 @@ int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType,
//图像信息
tpImage->iWidth = iWidth; tpImage->iHeight = iHeight; tpImage->iChannels = iChannels;
//内存尺寸
int _Size = iWidth*iHeight*iChannels;
int _Size = iWidth * iHeight * iChannels;
//分配所需内存
if (strcmp(ccSubType, "uint8_t") == 0) {
tpImage->iDepth = 0;
_Size *= sizeof(uint8_t);
tpImage->vpImage = (uint8_t *)malloc(_Size);
tpImage->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
......@@ -32,7 +32,7 @@ int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType,
else if (strcmp(ccSubType, "int8_t") == 0) {
tpImage->iDepth = 1;
_Size *= sizeof(int8_t);
tpImage->vpImage = (int8_t *)malloc(_Size);
tpImage->vpImage = (int8_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 128, _Size);
......@@ -40,7 +40,7 @@ int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType,
else if (strcmp(ccSubType, "uint16_t") == 0) {
tpImage->iDepth = 2;
_Size *= sizeof(uint16_t);
tpImage->vpImage = (uint16_t *)malloc(_Size);
tpImage->vpImage = (uint16_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
......@@ -48,7 +48,7 @@ int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType,
else if (strcmp(ccSubType, "int16_t") == 0) {
tpImage->iDepth = 3;
_Size *= sizeof(int16_t);
tpImage->vpImage = (int16_t *)malloc(_Size);
tpImage->vpImage = (int16_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
......@@ -56,7 +56,7 @@ int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType,
else if (strcmp(ccSubType, "int32_t") == 0) {
tpImage->iDepth = 4;
_Size *= sizeof(int32_t);
tpImage->vpImage = (int32_t *)malloc(_Size);
tpImage->vpImage = (int32_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
......@@ -64,7 +64,7 @@ int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType,
else if (strcmp(ccSubType, "float_t") == 0) {
tpImage->iDepth = 5;
_Size *= sizeof(float_t);
tpImage->vpImage = (float_t *)malloc(_Size);
tpImage->vpImage = (float_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
......@@ -72,7 +72,7 @@ int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType,
else if (strcmp(ccSubType, "double_t") == 0) {
tpImage->iDepth = 6;
_Size *= sizeof(double_t);
tpImage->vpImage = (double_t *)malloc(_Size);
tpImage->vpImage = (double_t*)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
......@@ -83,67 +83,64 @@ int eyemMatMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType,
return FUNC_OK;
}
int eyemMatCopy(EyemImage &vpDst, EyemImage vpSrc)
int eyemMatCopy(EyemImage vpSrc, EyemImage& vpDst)
{
CV_Assert(NULL != vpSrc.vpImage);
//在这里重新创建
if (NULL != vpDst.vpImage) {
_free(vpDst);
}
//图像信息
vpDst.iWidth = vpSrc.iWidth; vpDst.iHeight = vpSrc.iHeight; vpDst.iDepth = vpSrc.iDepth; vpDst.iChannels = vpSrc.iChannels;
//内存尺寸
int _Size = vpSrc.iWidth *vpSrc.iHeight *vpSrc.iChannels;
int _Size = vpSrc.iWidth * vpSrc.iHeight * vpSrc.iChannels;
switch (vpSrc.iDepth)
{
case CV_8U:
_Size *= sizeof(uint8_t);
vpDst.vpImage = (uint8_t *)malloc(_Size);
vpDst.vpImage = (uint8_t*)malloc(_Size);
if (NULL == vpDst.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpDst.vpImage, 0, _Size);
break;
case CV_8S:
_Size *= sizeof(int8_t);
vpDst.vpImage = (int8_t *)malloc(_Size);
vpDst.vpImage = (int8_t*)malloc(_Size);
if (NULL == vpDst.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpDst.vpImage, 0, _Size);
break;
case CV_16U:
_Size *= sizeof(uint16_t);
vpDst.vpImage = (uint16_t *)malloc(_Size);
vpDst.vpImage = (uint16_t*)malloc(_Size);
if (NULL == vpDst.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpDst.vpImage, 0, _Size);
break;
case CV_16S:
_Size *= sizeof(int16_t);
vpDst.vpImage = (int16_t *)malloc(_Size);
vpDst.vpImage = (int16_t*)malloc(_Size);
if (NULL == vpDst.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpDst.vpImage, 0, _Size);
break;
case CV_32S:
_Size *= sizeof(int32_t);
vpDst.vpImage = (int32_t *)malloc(_Size);
vpDst.vpImage = (int32_t*)malloc(_Size);
if (NULL == vpDst.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpDst.vpImage, 0, _Size);
break;
case CV_32F:
_Size *= sizeof(float_t);
vpDst.vpImage = (float_t *)malloc(_Size);
vpDst.vpImage = (float_t*)malloc(_Size);
if (NULL == vpDst.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpDst.vpImage, 0, _Size);
break;
case CV_64F:
_Size *= sizeof(double_t);
vpDst.vpImage = (double_t *)malloc(_Size);
vpDst.vpImage = (double_t*)malloc(_Size);
if (NULL == vpDst.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpDst.vpImage, 0, _Size);
......@@ -157,15 +154,13 @@ int eyemMatCopy(EyemImage &vpDst, EyemImage vpSrc)
return FUNC_OK;
}
int eyemMatAdd(EyemImage vpA, EyemImage vpB, EyemImage &vpC)
int eyemMatAdd(EyemImage vpA, EyemImage vpB, EyemImage& vpC)
{
//判断是否是空文件
CV_Assert(NULL != vpA.vpImage && NULL != vpB.vpImage);
//必须具有相同类型
CV_Assert(vpA.iWidth == vpB.iWidth&&vpA.iHeight == vpB.iHeight&&vpA.iDepth == vpB.iDepth&&vpA.iChannels == \
CV_Assert(vpA.iWidth == vpB.iWidth && vpA.iHeight == vpB.iHeight && vpA.iDepth == vpB.iDepth && vpA.iChannels == \
vpB.iChannels);
//在这里重新创建
if (NULL != vpC.vpImage) {
_free(vpC);
......@@ -176,59 +171,57 @@ int eyemMatAdd(EyemImage vpA, EyemImage vpB, EyemImage &vpC)
cv::Mat(vpB.iHeight, vpB.iWidth, MAKETYPE(vpB.iDepth, vpB.iChannels), vpB.vpImage), _dst);
//内存尺寸
int _Size = _dst.cols *_dst.rows *_dst.channels();
int _Size = _dst.cols * _dst.rows * _dst.channels();
//目标图像信息
vpC.iWidth = _dst.cols, vpC.iHeight = _dst.rows, vpC.iDepth = _dst.depth(), vpC.iChannels = _dst.channels();
//分配内存
switch (vpC.iDepth)
{
case CV_8U:
_Size *= sizeof(uint8_t);
vpC.vpImage = (uint8_t *)malloc(_Size);
vpC.vpImage = (uint8_t*)malloc(_Size);
if (NULL == vpC.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpC.vpImage, 0, _Size);
break;
case CV_8S:
_Size *= sizeof(int8_t);
vpC.vpImage = (int8_t *)malloc(_Size);
vpC.vpImage = (int8_t*)malloc(_Size);
if (NULL == vpC.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpC.vpImage, 0, _Size);
break;
case CV_16U:
_Size *= sizeof(uint16_t);
vpC.vpImage = (uint16_t *)malloc(_Size);
vpC.vpImage = (uint16_t*)malloc(_Size);
if (NULL == vpC.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpC.vpImage, 0, _Size);
break;
case CV_16S:
_Size *= sizeof(int16_t);
vpC.vpImage = (int16_t *)malloc(_Size);
vpC.vpImage = (int16_t*)malloc(_Size);
if (NULL == vpC.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpC.vpImage, 0, _Size);
break;
case CV_32S:
_Size *= sizeof(int32_t);
vpC.vpImage = (int32_t *)malloc(_Size);
vpC.vpImage = (int32_t*)malloc(_Size);
if (NULL == vpC.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpC.vpImage, 0, _Size);
break;
case CV_32F:
_Size *= sizeof(float_t);
vpC.vpImage = (float_t *)malloc(_Size);
vpC.vpImage = (float_t*)malloc(_Size);
if (NULL == vpC.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpC.vpImage, 0, _Size);
break;
case CV_64F:
_Size *= sizeof(double_t);
vpC.vpImage = (double_t *)malloc(_Size);
vpC.vpImage = (double_t*)malloc(_Size);
if (NULL == vpC.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(vpC.vpImage, 0, _Size);
......@@ -242,13 +235,13 @@ int eyemMatAdd(EyemImage vpA, EyemImage vpB, EyemImage &vpC)
return FUNC_OK;
}
int eyemMatSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage &tpDstImg)
int eyemMatSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage& tpDstImg)
{
CV_Assert(NULL != tpImageMinuend.vpImage || NULL != tpImageSubtrahend.vpImage);
//必须具有相同类型
CV_Assert(tpImageMinuend.iWidth == tpImageSubtrahend.iWidth&&tpImageMinuend.iHeight == tpImageSubtrahend.iHeight&&
tpImageMinuend.iDepth == tpImageSubtrahend.iDepth&&tpImageMinuend.iChannels == tpImageSubtrahend.iChannels);
CV_Assert(tpImageMinuend.iWidth == tpImageSubtrahend.iWidth && tpImageMinuend.iHeight == tpImageSubtrahend.iHeight &&
tpImageMinuend.iDepth == tpImageSubtrahend.iDepth && tpImageMinuend.iChannels == tpImageSubtrahend.iChannels);
//在这里重新创建
if (NULL != tpDstImg.vpImage) {
......@@ -262,7 +255,7 @@ int eyemMatSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage
tpImageSubtrahend.vpImage), _dst);
//内存尺寸
int _Size = _dst.cols *_dst.rows *_dst.channels();
int _Size = _dst.cols * _dst.rows * _dst.channels();
//目标图像信息
tpDstImg.iWidth = _dst.cols, tpDstImg.iHeight = _dst.rows, tpDstImg.iDepth = _dst.depth(), tpDstImg.iChannels = _dst.channels();
......@@ -271,49 +264,49 @@ int eyemMatSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage
{
case CV_8U:
_Size *= sizeof(uint8_t);
tpDstImg.vpImage = (uint8_t *)malloc(_Size);
tpDstImg.vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
break;
case CV_8S:
_Size *= sizeof(int8_t);
tpDstImg.vpImage = (int8_t *)malloc(_Size);
tpDstImg.vpImage = (int8_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
break;
case CV_16U:
_Size *= sizeof(uint16_t);
tpDstImg.vpImage = (uint16_t *)malloc(_Size);
tpDstImg.vpImage = (uint16_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
break;
case CV_16S:
_Size *= sizeof(int16_t);
tpDstImg.vpImage = (int16_t *)malloc(_Size);
tpDstImg.vpImage = (int16_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
break;
case CV_32S:
_Size *= sizeof(int32_t);
tpDstImg.vpImage = (int32_t *)malloc(_Size);
tpDstImg.vpImage = (int32_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
break;
case CV_32F:
_Size *= sizeof(float_t);
tpDstImg.vpImage = (float_t *)malloc(_Size);
tpDstImg.vpImage = (float_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
break;
case CV_64F:
_Size *= sizeof(double_t);
tpDstImg.vpImage = (double_t *)malloc(_Size);
tpDstImg.vpImage = (double_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
......@@ -327,7 +320,7 @@ int eyemMatSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage
return FUNC_OK;
}
int eyemMatAbs(EyemImage &tpImage)
int eyemMatAbs(EyemImage& tpImage)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat _src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
......@@ -336,56 +329,56 @@ int eyemMatAbs(EyemImage &tpImage)
//运算
cv::Mat _dst = cv::abs(_src);
//内存尺寸
int _Size = _dst.cols *_dst.rows *_dst.channels();
int _Size = _dst.cols * _dst.rows * _dst.channels();
//图像信息
tpImage.iWidth = _dst.cols, tpImage.iHeight = _dst.rows, tpImage.iDepth = _dst.depth(), tpImage.iChannels = _dst.channels();
switch (_dst.depth())
{
case CV_8U:
_Size *= sizeof(uint8_t);
tpImage.vpImage = (uint8_t *)malloc(_Size);
tpImage.vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
break;
case CV_8S:
_Size *= sizeof(int8_t);
tpImage.vpImage = (int8_t *)malloc(_Size);
tpImage.vpImage = (int8_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
break;
case CV_16U:
_Size *= sizeof(uint16_t);
tpImage.vpImage = (uint16_t *)malloc(_Size);
tpImage.vpImage = (uint16_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
break;
case CV_16S:
_Size *= sizeof(int16_t);
tpImage.vpImage = (int16_t *)malloc(_Size);
tpImage.vpImage = (int16_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
break;
case CV_32S:
_Size *= sizeof(int32_t);
tpImage.vpImage = (int32_t *)malloc(_Size);
tpImage.vpImage = (int32_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
break;
case CV_32F:
_Size *= sizeof(float_t);
tpImage.vpImage = (float_t *)malloc(_Size);
tpImage.vpImage = (float_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
break;
case CV_64F:
_Size *= sizeof(double_t);
tpImage.vpImage = (double_t *)malloc(_Size);
tpImage.vpImage = (double_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
......@@ -399,15 +392,15 @@ int eyemMatAbs(EyemImage &tpImage)
return FUNC_OK;
}
int eyemBitwiseNot(EyemImage &tpImage)
int eyemBitwiseNot(EyemImage& tpImage)
{
CV_Assert(NULL != tpImage.vpImage&&tpImage.iDepth == 0);
CV_Assert(NULL != tpImage.vpImage && tpImage.iDepth == 0);
cv::Mat _src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage);
cv::bitwise_not(_src, _src, cv::noArray());
return FUNC_OK;
}
int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, double beta, EyemImage &tpDstImg)
int eyemCvtImageType(EyemImage tpImage, const char* ccSubType, double alpha, double beta, EyemImage& tpDstImg)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat _src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
......@@ -416,7 +409,7 @@ int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, dou
_free(tpDstImg);
}
//内存尺寸(图像数据类型转换不涉及通道、尺寸)
int _Size = tpImage.iWidth*tpImage.iHeight*tpImage.iChannels;
int _Size = tpImage.iWidth * tpImage.iHeight * tpImage.iChannels;
//图像信息
tpDstImg.iWidth = tpImage.iWidth; tpDstImg.iHeight = tpImage.iHeight; tpDstImg.iChannels = tpImage.iChannels;
......@@ -426,7 +419,7 @@ int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, dou
if (strcmp(ccSubType, "uint8_t") == 0) {
tpDstImg.iDepth = 0;
_Size *= sizeof(uint8_t);
tpDstImg.vpImage = (uint8_t *)malloc(_Size);
tpDstImg.vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
......@@ -434,7 +427,7 @@ int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, dou
else if (strcmp(ccSubType, "int8_t") == 0) {
tpDstImg.iDepth = 1;
_Size *= sizeof(int8_t);
tpDstImg.vpImage = (int8_t *)malloc(_Size);
tpDstImg.vpImage = (int8_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
......@@ -442,7 +435,7 @@ int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, dou
else if (strcmp(ccSubType, "uint16_t") == 0) {
tpDstImg.iDepth = 2;
_Size *= sizeof(uint16_t);
tpDstImg.vpImage = (uint16_t *)malloc(_Size);
tpDstImg.vpImage = (uint16_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
......@@ -450,7 +443,7 @@ int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, dou
else if (strcmp(ccSubType, "int16_t") == 0) {
tpDstImg.iDepth = 3;
_Size *= sizeof(int16_t);
tpDstImg.vpImage = (int16_t *)malloc(_Size);
tpDstImg.vpImage = (int16_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
......@@ -458,7 +451,7 @@ int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, dou
else if (strcmp(ccSubType, "int32_t") == 0) {
tpDstImg.iDepth = 4;
_Size *= sizeof(int32_t);
tpDstImg.vpImage = (int32_t *)malloc(_Size);
tpDstImg.vpImage = (int32_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
......@@ -466,7 +459,7 @@ int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, dou
else if (strcmp(ccSubType, "float_t") == 0) {
tpDstImg.iDepth = 5;
_Size *= sizeof(float_t);
tpDstImg.vpImage = (float_t *)malloc(_Size);
tpDstImg.vpImage = (float_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
......@@ -474,7 +467,7 @@ int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, dou
else if (strcmp(ccSubType, "double_t") == 0) {
tpDstImg.iDepth = 6;
_Size *= sizeof(double_t);
tpDstImg.vpImage = (double_t *)malloc(_Size);
tpDstImg.vpImage = (double_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
......@@ -489,74 +482,68 @@ int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, dou
return FUNC_OK;
}
int eyemCvtImageColor(EyemImage tpImage, int iCCodes, EyemImage &tpDstImg)
int eyemCvtImageColor(EyemImage tpImage, int iCCodes, EyemImage& tpDstImg)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat _src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
//在这里重新创建
if (NULL != tpDstImg.vpImage) {
_free(tpDstImg);
}
//颜色空间转换
cv::Mat _dst;
cv::cvtColor(_src, _dst, iCCodes);
//内存尺寸
int _Size = tpImage.iWidth *tpImage.iHeight *_dst.channels();
int _Size = tpImage.iWidth * tpImage.iHeight * _dst.channels();
//目标图像信息
tpDstImg.iWidth = _dst.cols, tpDstImg.iHeight = _dst.rows, tpDstImg.iDepth = _dst.depth(), tpDstImg.iChannels = _dst.channels();
switch (tpDstImg.iDepth)
{
case CV_8U:
_Size *= sizeof(uint8_t);
tpDstImg.vpImage = (uint8_t *)malloc(_Size);
tpDstImg.vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
break;
case CV_8S:
_Size *= sizeof(int8_t);
tpDstImg.vpImage = (int8_t *)malloc(_Size);
tpDstImg.vpImage = (int8_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
break;
case CV_16U:
_Size *= sizeof(uint16_t);
tpDstImg.vpImage = (uint16_t *)malloc(_Size);
tpDstImg.vpImage = (uint16_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
break;
case CV_16S:
_Size *= sizeof(int16_t);
tpDstImg.vpImage = (int16_t *)malloc(_Size);
tpDstImg.vpImage = (int16_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
break;
case CV_32S:
_Size *= sizeof(int32_t);
tpDstImg.vpImage = (int32_t *)malloc(_Size);
tpDstImg.vpImage = (int32_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
break;
case CV_32F:
_Size *= sizeof(float_t);
tpDstImg.vpImage = (float_t *)malloc(_Size);
tpDstImg.vpImage = (float_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
break;
case CV_64F:
_Size *= sizeof(double_t);
tpDstImg.vpImage = (double_t *)malloc(_Size);
tpDstImg.vpImage = (double_t*)malloc(_Size);
if (NULL == tpDstImg.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg.vpImage, 0, _Size);
......@@ -570,7 +557,7 @@ int eyemCvtImageColor(EyemImage tpImage, int iCCodes, EyemImage &tpDstImg)
return FUNC_OK;
}
int eyemDecompose(EyemImage tpImage, EyemImage *tpDstImgR, EyemImage *tpDstImgG, EyemImage *tpDstImgB)
int eyemDecompose(EyemImage tpImage, EyemImage* tpDstImgR, EyemImage* tpDstImgG, EyemImage* tpDstImgB)
{
CV_Assert(NULL != tpImage.vpImage);
......@@ -587,24 +574,24 @@ int eyemDecompose(EyemImage tpImage, EyemImage *tpDstImgR, EyemImage *tpDstImgG,
tpDstImgR->iDepth = tpDstImgG->iDepth = tpDstImgB->iDepth = tpImage.iDepth;
tpDstImgR->iChannels = tpDstImgG->iChannels = tpDstImgB->iChannels = 1;
//内存尺寸
int _Size = tpDstImgR->iWidth*tpDstImgR->iHeight*tpDstImgR->iChannels * sizeof(uint8_t);
int _Size = tpDstImgR->iWidth * tpDstImgR->iHeight * tpDstImgR->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImgR->vpImage = (uint8_t *)malloc(_Size);
tpDstImgR->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImgR->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImgR->vpImage, 0, _Size);
//拷贝数据
memcpy(tpDstImgR->vpImage, mv[2].data, _Size);
tpDstImgG->vpImage = (uint8_t *)malloc(_Size);
tpDstImgG->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImgG->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImgG->vpImage, 0, _Size);
//拷贝数据
memcpy(tpDstImgG->vpImage, mv[1].data, _Size);
tpDstImgB->vpImage = (uint8_t *)malloc(_Size);
tpDstImgB->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImgB->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImgB->vpImage, 0, _Size);
......@@ -622,7 +609,7 @@ int eyemMatAt(EyemImage tpImage, EyemOcsIXY tpPoint)
return FUNC_OK;
}
int eyemNormalize(EyemImage &tpImage)
int eyemNormalize(EyemImage& tpImage)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
......@@ -638,17 +625,17 @@ int eyemNormalize(EyemImage &tpImage)
uint8_t b, g, r;
float bgr = (float)(image.ptr<cv::Vec3b>(y)[x][0] + image.ptr<cv::Vec3b>(y)[x][1] + image.ptr<cv::Vec3b>(y)[x][2]);
bgr = bgr == 0 ? 1 : 1.0f / bgr;
b = cvRound(255.0f*(float)image.ptr<cv::Vec3b>(y)[x][0] * bgr);
g = cvRound(255.0f*(float)image.ptr<cv::Vec3b>(y)[x][1] * bgr);
r = cvRound(255.0f*(float)image.ptr<cv::Vec3b>(y)[x][2] * bgr);
b = cvRound(255.0f * (float)image.ptr<cv::Vec3b>(y)[x][0] * bgr);
g = cvRound(255.0f * (float)image.ptr<cv::Vec3b>(y)[x][1] * bgr);
r = cvRound(255.0f * (float)image.ptr<cv::Vec3b>(y)[x][2] * bgr);
image.ptr<cv::Vec3b>(y)[x] = cv::Vec3b(b, g, r);
}
}
});
});
//输出
tpImage.iWidth = image.cols; tpImage.iHeight = image.rows; tpImage.iDepth = image.depth(); tpImage.iChannels = image.channels();
int _Size = image.cols *image.rows *image.channels() * sizeof(uint8_t);
tpImage.vpImage = (uint8_t *)malloc(_Size);
int _Size = image.cols * image.rows * image.channels() * sizeof(uint8_t);
tpImage.vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpImage.vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage.vpImage, 0, _Size);
......@@ -657,7 +644,7 @@ int eyemNormalize(EyemImage &tpImage)
return FUNC_OK;
}
int eyemScaleImage(EyemImage tpImage, EyemImage *tpDstImg)
int eyemScaleImage(EyemImage tpImage, EyemImage* tpDstImg)
{
CV_Assert(NULL != tpImage.vpImage);
......@@ -666,7 +653,7 @@ int eyemScaleImage(EyemImage tpImage, EyemImage *tpDstImg)
return FUNC_OK;
}
int eyemScaleImageMax(EyemImage tpImage, EyemImage *tpDstImg)
int eyemScaleImageMax(EyemImage tpImage, EyemImage* tpDstImg)
{
CV_Assert(NULL != tpImage.vpImage);
......@@ -676,7 +663,7 @@ int eyemScaleImageMax(EyemImage tpImage, EyemImage *tpDstImg)
return FUNC_OK;
}
int eyemWarpShiftSubpix(EyemImage tpImage, double dShiftX, double dShiftY, EyemImage *tpDstImg, int iInterMethod = 1)
int eyemWarpShiftSubpix(EyemImage tpImage, double dShiftX, double dShiftY, EyemImage* tpDstImg, int iInterMethod = 1)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
......@@ -694,6 +681,7 @@ int eyemWarpShiftSubpix(EyemImage tpImage, double dShiftX, double dShiftY, EyemI
cv::Mat imageShift;
cv::warpAffine(image, imageShift, matM, image.size(), iInterMethod, 0);
cv::imwrite("shift.png", imageShift);
return FUNC_OK;
}
......@@ -709,12 +697,12 @@ bool eyemCheckBinary(EyemImage tpImage)
if (incn != 1) {
return false;
}
int bs = 16, b = (X*incn) / bs, stride = (int)image.step;
int bs = 16, b = (X * incn) / bs, stride = (int)image.step;
for (int y = 0; y < Y; y++)
{
unsigned char *ptr = image.data + y * stride;
unsigned char* ptr = image.data + y * stride;
for (int x = 0; x < b * bs; x += bs) {
__m128i SrcV = _mm_loadu_si128((__m128i *)(ptr + x));
__m128i SrcV = _mm_loadu_si128((__m128i*)(ptr + x));
__m128i MaskW = _mm_cmpeq_epi8(SrcV, _mm_set1_epi8(255));
__m128i MaskB = _mm_cmpeq_epi8(SrcV, _mm_setzero_si128());
__m128i Mask = _mm_or_si128(MaskW, MaskB);
......@@ -729,4 +717,85 @@ bool eyemCheckBinary(EyemImage tpImage)
}
}
return true;
}
int eyemCopyRegion(EyemImage& tpImage, EyemRect 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();
//图像尺寸
const int X = image.cols, Y = image.rows;
//图像裁剪
cv::Mat _dst = image(cv::Rect(tpRoi.iXs, tpRoi.iYs, tpRoi.iWidth, tpRoi.iHeight) & cv::Rect(0, 0, X, Y)).clone();
//内存尺寸
int _Size = _dst.cols * _dst.rows * _dst.channels();
//图像信息
tpDstImg->iWidth = _dst.cols, tpDstImg->iHeight = _dst.rows, tpDstImg->iDepth = _dst.depth(), tpDstImg->iChannels = _dst.channels();
switch (_dst.depth())
{
case CV_8U:
_Size *= sizeof(uint8_t);
tpDstImg->vpImage = (uint8_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
break;
case CV_8S:
_Size *= sizeof(int8_t);
tpDstImg->vpImage = (int8_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
break;
case CV_16U:
_Size *= sizeof(uint16_t);
tpDstImg->vpImage = (uint16_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
break;
case CV_16S:
_Size *= sizeof(int16_t);
tpDstImg->vpImage = (int16_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
break;
case CV_32S:
_Size *= sizeof(int32_t);
tpDstImg->vpImage = (int32_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
break;
case CV_32F:
_Size *= sizeof(float_t);
tpDstImg->vpImage = (float_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
break;
case CV_64F:
_Size *= sizeof(double_t);
tpDstImg->vpImage = (double_t*)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
break;
default:
//no support format
return FUNC_ILLEGAL_ARGUMENT;
}
//拷贝数据
memcpy(tpDstImg->vpImage, _dst.data, _Size);
return FUNC_OK;
}
int eyemCountNonZero(EyemImage& tpImage)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty())
return 0;
return cv::countNonZero(image);
}
\ No newline at end of file
此文件的差异太大,无法显示。
......@@ -18,51 +18,55 @@ extern double processLevel;
extern double fineTuning;
extern std::map<std::string, EyemImage> imageMap;
class PreSegtor {
public:
PreSegtor(const std::string& model_path);
PreSegtor() {};
//设置检测参数
cv::Mat extract(cv::InputArray img);
protected:
class Impl;
cv::Ptr<Impl> p;
};
class PreSegtor::Impl {
public:
Impl() {}
~Impl() {}
//提取
cv::Mat forward(cv::Mat& img);
//特征提取器
std::shared_ptr<AZONNXWrapperEx> extractor_;
};
PreSegtor::PreSegtor(const std::string& model_path)
{
p = cv::makePtr<PreSegtor::Impl>();
if (!model_path.empty()) {
p->extractor_ = std::make_shared<AZONNXWrapperEx>();
p->extractor_->init(model_path);
}
else {
p->extractor_ = NULL;
}
}
cv::Mat PreSegtor::extract(cv::InputArray img)
{
return p->forward(img.getMat());
}
cv::Mat PreSegtor::Impl::forward(cv::Mat& img)
{
return extractor_->forward(img);
}
#ifdef _V455
//class PreSegtor {
//public:
// PreSegtor(const std::string& model_path);
// PreSegtor() {};
// //设置检测参数
// cv::Mat extract(cv::InputArray img);
//
//protected:
// class Impl;
// cv::Ptr<Impl> p;
//};
//
//class PreSegtor::Impl {
//public:
// Impl() {}
// ~Impl() {}
// //提取
// cv::Mat forward(cv::Mat& img);
// //特征提取器
// std::shared_ptr<AZONNXWrapperEx> extractor_;
//};
//
//PreSegtor::PreSegtor(const std::string& model_path)
//{
// p = cv::makePtr<PreSegtor::Impl>();
// if (!model_path.empty()) {
// p->extractor_ = std::make_shared<AZONNXWrapperEx>();
// p->extractor_->init(model_path);
// }
// else {
// p->extractor_ = NULL;
// }
//}
//
//cv::Mat PreSegtor::extract(cv::InputArray img)
//{
// return p->forward(img.getMat());
//}
//
//
//cv::Mat PreSegtor::Impl::forward(cv::Mat& img)
//{
// return extractor_->forward(img);
//}
//
//cv::Ptr<PreSegtor> pSegtor;
#endif
cv::Ptr<PreSegtor> pSegtor;
#endif/* __EYEM_MISC_H */
......@@ -17,12 +17,12 @@ int ncc_based_matching::getTopLayer(cv::Mat& matTempl, int iMinDstLength)
cv::Point2f ncc_based_matching::ptRotatePt2f(cv::Point2f ptInput, cv::Point2f ptOrg, double dAngle)
{
double dWidth = ptOrg.x * 2;
double dHeight = ptOrg.y * 2;
double dWidth = (double)ptOrg.x * 2;
double dHeight = (double)ptOrg.y * 2;
double dY1 = dHeight - ptInput.y, dY2 = dHeight - ptOrg.y;
double dX = (ptInput.x - ptOrg.x) * cos(dAngle) - (dY1 - ptOrg.y) * sin(dAngle) + ptOrg.x;
double dY = (ptInput.x - ptOrg.x) * sin(dAngle) + (dY1 - ptOrg.y) * cos(dAngle) + dY2;
double dX = ((double)ptInput.x - (double)ptOrg.x) * cos(dAngle) - (dY1 - ptOrg.y) * sin(dAngle) + ptOrg.x;
double dY = ((double)ptInput.x - (double)ptOrg.x) * sin(dAngle) + (dY1 - ptOrg.y) * cos(dAngle) + dY2;
dY = -dY + dHeight;
return cv::Point2f((float)dX, (float)dY);
......@@ -88,7 +88,7 @@ void ncc_based_matching::TM_CCOEFF_Denominator(cv::Mat& matSrc, s_TemplData* pTe
matResult = cv::Scalar::all(1);
return;
}
double *q0 = 0, *q1 = 0, *q2 = 0, *q3 = 0;
double* q0 = 0, * q1 = 0, * q2 = 0, * q3 = 0;
cv::Mat sum, sqsum;
integral(matSrc, sum, sqsum, CV_32F, CV_64F);
......@@ -102,7 +102,7 @@ void ncc_based_matching::TM_CCOEFF_Denominator(cv::Mat& matSrc, s_TemplData* pTe
float* p0 = (float*)sum.data;
float* p1 = p0 + pTemplData->vecPyramid[iLayer].cols;
float* p2 = (float*)(sum.data + pTemplData->vecPyramid[iLayer].rows*sum.step);
float* p2 = (float*)(sum.data + pTemplData->vecPyramid[iLayer].rows * sum.step);
float* p3 = p2 + pTemplData->vecPyramid[iLayer].cols;
int sumstep = sum.data ? (int)(sum.step / sizeof(float)) : 0;
......@@ -371,7 +371,7 @@ BOOL ncc_based_matching::subPixEsimation(std::vector<s_MatchParameter>* vec, dou
//[ t* ] = [ k4 k5 2k2 ] [ -k8 ]
//solve (matA, matS, matZ, DECOMP_SVD);
matZ = (matA.t() * matA).inv() * matA.t()* matS;
matZ = (matA.t() * matA).inv() * matA.t() * matS;
cv::Mat matZ_t;
transpose(matZ, matZ_t);
double* dZ = matZ_t.ptr<double>(0);
......@@ -430,6 +430,8 @@ int ncc_based_matching::create_ncc_model(cv::Mat& tpTemplate, int iMinReduceArea
templData->iTopLayer = getTopLayer(tpTemplate, (int)sqrt((double)iMinReduceArea));
cv::buildPyramid(tpTemplate, m_TemplData.vecPyramid, templData->iTopLayer);
templData->iWidth = tpTemplate.cols; templData->iHeight = tpTemplate.rows;
int iSize = (int)templData->vecPyramid.size();
templData->resize(iSize);
......@@ -464,11 +466,15 @@ int ncc_based_matching::create_ncc_model(cv::Mat& tpTemplate, int iMinReduceArea
int ncc_based_matching::find_ncc_model(cv::Mat& tpImage, double dToleranceAngle, int iNumMatches, double dMaxOverlap, double dScore, float* fCenterX, float* fCenterY, float* fMatchScore, float* fMatchAngle)
{
s_TemplData* pTemplData = &m_TemplData;
if (!pTemplData->bIsPatternLearned)
return -1;
tpImage.copyTo(m_matSrc);
cv::cvtColor(m_matSrc, showResult, cv::COLOR_GRAY2BGR);
////用于处理部分超出边界
//cv::copyMakeBorder(tpImage, tpImage, pTemplData->iHeight, pTemplData->iHeight, pTemplData->iWidth, pTemplData->iWidth, cv::BORDER_REPLICATE);
//设定金字塔层数,总共1+iLayer层
int iTopLayer = pTemplData->iTopLayer;
......@@ -525,7 +531,7 @@ int ncc_based_matching::find_ncc_model(cv::Mat& tpImage, double dToleranceAngle,
}
}
filterWithScore(&vecMatchParameter, dScore - 0.05*iTopLayer);
filterWithScore(&vecMatchParameter, dScore - 0.05 * iTopLayer);
//紀錄旋轉矩形、ROI與角度
int iMatchSize = (int)vecMatchParameter.size();
......@@ -683,15 +689,33 @@ int ncc_based_matching::find_ncc_model(cv::Mat& tpImage, double dToleranceAngle,
sstm.dMatchedAngle = -vecAllResult[i].dMatchAngle;
sstm.dMatchScore = vecAllResult[i].dMatchScore;
//sstm.ptCenter -= cv::Point2d(pTemplData->iWidth, pTemplData->iHeight);
//sstm.ptLB -= cv::Point2d(pTemplData->iWidth, pTemplData->iHeight);
//sstm.ptLT -= cv::Point2d(pTemplData->iWidth, pTemplData->iHeight);
//sstm.ptRB -= cv::Point2d(pTemplData->iWidth, pTemplData->iHeight);
//sstm.ptRT -= cv::Point2d(pTemplData->iWidth, pTemplData->iHeight);
//cv::Mat region;
//int flag = cv::rotatedRectangleIntersection(cv::RotatedRect(cv::Point2f(0, 0), cv::Point2f(m_matSrc.cols, 0), cv::Point2f(m_matSrc.cols, m_matSrc.rows)),
// cv::RotatedRect(sstm.ptLT, sstm.ptRT, sstm.ptRB), region);
if (sstm.dMatchedAngle < -180)
sstm.dMatchedAngle += 360;
if (sstm.dMatchedAngle > 180)
sstm.dMatchedAngle -= 360;
m_vecSingleTargetData.push_back(sstm);
if (i + 1 == iNumMatches)
//if (flag > 0) {
m_vecSingleTargetData.push_back(sstm);
//}
if (m_vecSingleTargetData.size() == iNumMatches)
break;
}
iMatchSize = m_vecSingleTargetData.size();
//当设置的数量少于实际数量时仅返回设置数量
if (iNumMatches < iMatchSize) {
iMatchSize = iNumMatches;
}
//输出结果
for (int i = 0; i < iMatchSize; i++)
{
......@@ -713,10 +737,12 @@ void ncc_based_matching::draw_match_shapes()
cv::Point ptRB(m_vecSingleTargetData[i].ptRB);
cv::Point ptRT(m_vecSingleTargetData[i].ptRT);
cv::Point ptC(m_vecSingleTargetData[i].ptCenter);
drawDashLine(showResult, ptLT, ptLB);
drawDashLine(showResult, ptLB, ptRB);
drawDashLine(showResult, ptRB, ptRT);
drawDashLine(showResult, ptRT, ptLT);
//drawDashLine(showResult, ptLT, ptLB);
//drawDashLine(showResult, ptLB, ptRB);
//drawDashLine(showResult, ptRB, ptRT);
//drawDashLine(showResult, ptRT, ptLT);
cv::drawMarker(showResult, ptC, cv::Scalar(0, 255, 0), 0, 30, 1, cv::LINE_AA);
//左上及角落邊框
cv::Point ptDis1, ptDis2;
......@@ -730,29 +756,29 @@ void ncc_based_matching::draw_match_shapes()
ptDis1 = (ptLB - ptLT) / 3 * (m_matDst.cols / (float)m_matDst.rows);
ptDis2 = (ptRT - ptLT) / 3;
}
line(showResult, ptLT, ptLT + ptDis1 / 2, cv::Scalar(0, 255, 0), 1, cv::LINE_AA);
line(showResult, ptLT, ptLT + ptDis2 / 2, cv::Scalar(0, 255, 0), 1, cv::LINE_AA);
line(showResult, ptRT, ptRT + ptDis1 / 2, cv::Scalar(0, 255, 0), 1, cv::LINE_AA);
line(showResult, ptRT, ptRT - ptDis2 / 2, cv::Scalar(0, 255, 0), 1, cv::LINE_AA);
line(showResult, ptRB, ptRB - ptDis1 / 2, cv::Scalar(0, 255, 0), 1, cv::LINE_AA);
line(showResult, ptRB, ptRB - ptDis2 / 2, cv::Scalar(0, 255, 0), 1, cv::LINE_AA);
line(showResult, ptLB, ptLB - ptDis1 / 2, cv::Scalar(0, 255, 0), 1, cv::LINE_AA);
line(showResult, ptLB, ptLB + ptDis2 / 2, cv::Scalar(0, 255, 0), 1, cv::LINE_AA);
line(showResult, ptLT, ptLT + ptDis1 / 2, cv::Scalar(0, 140, 255), 1, cv::LINE_AA);
line(showResult, ptLT, ptLT + ptDis2 / 2, cv::Scalar(0, 140, 255), 1, cv::LINE_AA);
line(showResult, ptRT, ptRT + ptDis1 / 2, cv::Scalar(0, 140, 255), 1, cv::LINE_AA);
line(showResult, ptRT, ptRT - ptDis2 / 2, cv::Scalar(0, 140, 255), 1, cv::LINE_AA);
line(showResult, ptRB, ptRB - ptDis1 / 2, cv::Scalar(0, 140, 255), 1, cv::LINE_AA);
line(showResult, ptRB, ptRB - ptDis2 / 2, cv::Scalar(0, 140, 255), 1, cv::LINE_AA);
line(showResult, ptLB, ptLB - ptDis1 / 2, cv::Scalar(0, 140, 255), 1, cv::LINE_AA);
line(showResult, ptLB, ptLB + ptDis2 / 2, cv::Scalar(0, 140, 255), 1, cv::LINE_AA);
//
drawDashLine(showResult, ptLT + ptDis1, ptLT + ptDis2);
drawMarkCross(showResult, ptC.x, ptC.y, 5, cv::Scalar(0, 255, 0), 1);
cv::arrowedLine(showResult, ptC, ptRT/*cv::Point(ptRT + ptRB) / 2*/, cv::Scalar(25, 255, 0), 1, cv::LINE_AA);
//drawDashLine(showResult, ptLT + ptDis1, ptLT + ptDis2);
//drawMarkCross(showResult, ptC.x, ptC.y, 1, cv::Scalar(0, 255, 0), 1);
std::string str = cv::format("%d", i);
putText(showResult, str, (ptLT + ptRT) / 2, cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(0, 255, 0));
putText(showResult, str, (ptLT + ptRT) / 2, cv::FONT_HERSHEY_PLAIN, 2, cv::Scalar(0, 0, 255), 2);
}
}
int eyemMakeNCCModel(EyemImage tpImage, int iMinReduceArea)
{
CV_Assert(NULL != tpImage.vpImage);
//CV_Assert(NULL != tpImage.vpImage);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty())
return FUNC_IMAGE_NOT_EXIST;
//仅支持灰度图
......@@ -765,12 +791,10 @@ int eyemMakeNCCModel(EyemImage tpImage, int iMinReduceArea)
return FUNC_OK;
}
int eyemFindNCCModel(EyemImage tpImage, double dToleranceAngle, int iNumMatches, double dMaxOverlap, double dScore, EyemTargetMatch *tpResults)
int eyemFindNCCModel(EyemImage tpImage, double dToleranceAngle, int iNumMatches, double dMaxOverlap, double dScore, bool bDrawResult, EyemTargetMatch* tpResults, EyemImage* tpDstImg)
{
CV_Assert(NULL != tpImage.vpImage);
//CV_Assert(NULL != tpImage.vpImage);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty())
return FUNC_IMAGE_NOT_EXIST;
......@@ -780,28 +804,53 @@ int eyemFindNCCModel(EyemImage tpImage, double dToleranceAngle, int iNumMatches,
cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
}
//清空结果
memset(tpResults, 0, iNumMatches*sizeof(EyemTargetMatch));
memset(tpResults, 0, iNumMatches * sizeof(EyemTargetMatch));
//匹配模板
float* _fCenterX = new float[iNumMatches]; float* _fCenterY = new float[iNumMatches]; float* _fMatchScore = new float[iNumMatches]; float* _fMatchAngle = new float[iNumMatches];
int iSize = nbm.find_ncc_model(image, dToleranceAngle, iNumMatches, dMaxOverlap, dScore, _fCenterX, _fCenterY, _fMatchScore, _fMatchAngle);
if (iSize <= 0) {
float* fCenterX = new float[iNumMatches]; float* fCenterY = new float[iNumMatches]; float* fMatchScore = new float[iNumMatches]; float* fMatchAngle = new float[iNumMatches];
int iSize = nbm.find_ncc_model(image, dToleranceAngle, iNumMatches, dMaxOverlap, dScore, fCenterX, fCenterY, fMatchScore, fMatchAngle);
if (iSize == 0) {
return FUNC_FAILED_DETECT;
}
//未创建模板无法使用
if (iSize < 0) {
return FUNC_CANNOT_USE;
}
//输出结果
for (int i = 0; i < iSize; i++)
for (int i = 0; i < iSize && i < iNumMatches; i++)
{
tpResults[i].fCenterX = _fCenterX[i];
tpResults[i].fCenterY = _fCenterY[i];
tpResults[i].fMatchScore = _fMatchScore[i];
tpResults[i].fMatchAngle = _fMatchAngle[i];
tpResults[i].fCenterX = fCenterX[i];
tpResults[i].fCenterY = fCenterY[i];
tpResults[i].fMatchScore = fMatchScore[i];
tpResults[i].fMatchAngle = fMatchAngle[i];
}
//画图
nbm.draw_match_shapes();
if (bDrawResult) {
//释放可能的资源
if (NULL != tpDstImg->vpImage) {
tpDstImg->iWidth = tpDstImg->iHeight = tpDstImg->iDepth = tpDstImg->iChannels = 0;
//释放
free(tpDstImg->vpImage);
tpDstImg->vpImage = NULL;
}
nbm.draw_match_shapes();
cv::Mat result = nbm.getResultMat();
//<输出结果图像
tpDstImg->iWidth = result.cols; tpDstImg->iHeight = result.rows; tpDstImg->iDepth = result.depth(); tpDstImg->iChannels = result.channels();
//内存尺寸
int _Size_ = tpDstImg->iWidth * tpDstImg->iHeight * tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImg->vpImage = (uint8_t*)malloc(_Size_);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size_);
//拷贝数据
memcpy(tpDstImg->vpImage, result.data, _Size_);
}
//释放资源
delete[] _fCenterX; delete[] _fCenterY; delete[] _fMatchScore; delete[] _fMatchAngle;
_fCenterX = NULL; _fCenterY = NULL; _fMatchScore = NULL; _fMatchAngle = NULL;
delete[] fCenterX; delete[] fCenterY; delete[] fMatchScore; delete[] fMatchAngle;
fCenterX = NULL; fCenterY = NULL; fMatchScore = NULL; fMatchAngle = NULL;
return FUNC_OK;
}
......@@ -19,6 +19,8 @@ public:
void draw_match_shapes();
cv::Mat getResultMat() { return showResult; }
private:
struct s_TemplData
{
......@@ -28,7 +30,7 @@ private:
std::vector<double> vecInvArea;
std::vector<BOOL> vecResultEqual1;
BOOL bIsPatternLearned;
int iTopLayer;
int iTopLayer, iWidth, iHeight;
void clear()
{
std::vector<cv::Mat>().swap(vecPyramid);
......@@ -47,7 +49,7 @@ private:
s_TemplData()
{
bIsPatternLearned = FALSE;
iTopLayer = 0;
iTopLayer = iWidth = iHeight = 0;
}
};
struct s_MatchParameter
......
此文件太大,无法显示。
此文件类型无法预览
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!