Commit 04c03c6d 张士柳

1 个父辈 1181d725
......@@ -4,24 +4,13 @@ using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
namespace eyemLib_Sharp
{
public unsafe class EyemLib
{
#region 图像常量
public static readonly int CV_8U = 0;
public static readonly int CV_8S = 1;
public static readonly int CV_16U = 2;
public static readonly int CV_16S = 3;
public static readonly int CV_32S = 4;
public static readonly int CV_32F = 5;
public static readonly int CV_64F = 6;
#endregion
#region 枚举
//稳健估计方法
......@@ -40,6 +29,275 @@ namespace eyemLib_Sharp
EYEM_DIST_ATLWORTH = 10
}
//图像格式信息
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_BGR2BGR565 = 12, //!< convert between RGB/BGR and BGR565 (16-bit images)
COLOR_RGB2BGR565 = 13,
COLOR_BGR5652BGR = 14,
COLOR_BGR5652RGB = 15,
COLOR_BGRA2BGR565 = 16,
COLOR_RGBA2BGR565 = 17,
COLOR_BGR5652BGRA = 18,
COLOR_BGR5652RGBA = 19,
COLOR_GRAY2BGR565 = 20, //!< convert between grayscale to BGR565 (16-bit images)
COLOR_BGR5652GRAY = 21,
COLOR_BGR2BGR555 = 22, //!< convert between RGB/BGR and BGR555 (16-bit images)
COLOR_RGB2BGR555 = 23,
COLOR_BGR5552BGR = 24,
COLOR_BGR5552RGB = 25,
COLOR_BGRA2BGR555 = 26,
COLOR_RGBA2BGR555 = 27,
COLOR_BGR5552BGRA = 28,
COLOR_BGR5552RGBA = 29,
COLOR_GRAY2BGR555 = 30, //!< convert between grayscale and BGR555 (16-bit images)
COLOR_BGR5552GRAY = 31,
COLOR_BGR2XYZ = 32, //!< convert RGB/BGR to CIE XYZ, @ref color_convert_rgb_xyz "color conversions"
COLOR_RGB2XYZ = 33,
COLOR_XYZ2BGR = 34,
COLOR_XYZ2RGB = 35,
COLOR_BGR2YCrCb = 36, //!< convert RGB/BGR to luma-chroma (aka YCC), @ref color_convert_rgb_ycrcb "color conversions"
COLOR_RGB2YCrCb = 37,
COLOR_YCrCb2BGR = 38,
COLOR_YCrCb2RGB = 39,
COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions"
COLOR_RGB2HSV = 41,
COLOR_BGR2Lab = 44, //!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions"
COLOR_RGB2Lab = 45,
COLOR_BGR2Luv = 50, //!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions"
COLOR_RGB2Luv = 51,
COLOR_BGR2HLS = 52, //!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions"
COLOR_RGB2HLS = 53,
COLOR_HSV2BGR = 54, //!< backward conversions to RGB/BGR
COLOR_HSV2RGB = 55,
COLOR_Lab2BGR = 56,
COLOR_Lab2RGB = 57,
COLOR_Luv2BGR = 58,
COLOR_Luv2RGB = 59,
COLOR_HLS2BGR = 60,
COLOR_HLS2RGB = 61,
COLOR_BGR2HSV_FULL = 66,
COLOR_RGB2HSV_FULL = 67,
COLOR_BGR2HLS_FULL = 68,
COLOR_RGB2HLS_FULL = 69,
COLOR_HSV2BGR_FULL = 70,
COLOR_HSV2RGB_FULL = 71,
COLOR_HLS2BGR_FULL = 72,
COLOR_HLS2RGB_FULL = 73,
COLOR_LBGR2Lab = 74,
COLOR_LRGB2Lab = 75,
COLOR_LBGR2Luv = 76,
COLOR_LRGB2Luv = 77,
COLOR_Lab2LBGR = 78,
COLOR_Lab2LRGB = 79,
COLOR_Luv2LBGR = 80,
COLOR_Luv2LRGB = 81,
COLOR_BGR2YUV = 82, //!< convert between RGB/BGR and YUV
COLOR_RGB2YUV = 83,
COLOR_YUV2BGR = 84,
COLOR_YUV2RGB = 85,
//! YUV 4:2:0 family to RGB
COLOR_YUV2RGB_NV12 = 90,
COLOR_YUV2BGR_NV12 = 91,
COLOR_YUV2RGB_NV21 = 92,
COLOR_YUV2BGR_NV21 = 93,
COLOR_YUV420sp2RGB = COLOR_YUV2RGB_NV21,
COLOR_YUV420sp2BGR = COLOR_YUV2BGR_NV21,
COLOR_YUV2RGBA_NV12 = 94,
COLOR_YUV2BGRA_NV12 = 95,
COLOR_YUV2RGBA_NV21 = 96,
COLOR_YUV2BGRA_NV21 = 97,
COLOR_YUV420sp2RGBA = COLOR_YUV2RGBA_NV21,
COLOR_YUV420sp2BGRA = COLOR_YUV2BGRA_NV21,
COLOR_YUV2RGB_YV12 = 98,
COLOR_YUV2BGR_YV12 = 99,
COLOR_YUV2RGB_IYUV = 100,
COLOR_YUV2BGR_IYUV = 101,
COLOR_YUV2RGB_I420 = COLOR_YUV2RGB_IYUV,
COLOR_YUV2BGR_I420 = COLOR_YUV2BGR_IYUV,
COLOR_YUV420p2RGB = COLOR_YUV2RGB_YV12,
COLOR_YUV420p2BGR = COLOR_YUV2BGR_YV12,
COLOR_YUV2RGBA_YV12 = 102,
COLOR_YUV2BGRA_YV12 = 103,
COLOR_YUV2RGBA_IYUV = 104,
COLOR_YUV2BGRA_IYUV = 105,
COLOR_YUV2RGBA_I420 = COLOR_YUV2RGBA_IYUV,
COLOR_YUV2BGRA_I420 = COLOR_YUV2BGRA_IYUV,
COLOR_YUV420p2RGBA = COLOR_YUV2RGBA_YV12,
COLOR_YUV420p2BGRA = COLOR_YUV2BGRA_YV12,
COLOR_YUV2GRAY_420 = 106,
COLOR_YUV2GRAY_NV21 = COLOR_YUV2GRAY_420,
COLOR_YUV2GRAY_NV12 = COLOR_YUV2GRAY_420,
COLOR_YUV2GRAY_YV12 = COLOR_YUV2GRAY_420,
COLOR_YUV2GRAY_IYUV = COLOR_YUV2GRAY_420,
COLOR_YUV2GRAY_I420 = COLOR_YUV2GRAY_420,
COLOR_YUV420sp2GRAY = COLOR_YUV2GRAY_420,
COLOR_YUV420p2GRAY = COLOR_YUV2GRAY_420,
//! YUV 4:2:2 family to RGB
COLOR_YUV2RGB_UYVY = 107,
COLOR_YUV2BGR_UYVY = 108,
//COLOR_YUV2RGB_VYUY = 109,
//COLOR_YUV2BGR_VYUY = 110,
COLOR_YUV2RGB_Y422 = COLOR_YUV2RGB_UYVY,
COLOR_YUV2BGR_Y422 = COLOR_YUV2BGR_UYVY,
COLOR_YUV2RGB_UYNV = COLOR_YUV2RGB_UYVY,
COLOR_YUV2BGR_UYNV = COLOR_YUV2BGR_UYVY,
COLOR_YUV2RGBA_UYVY = 111,
COLOR_YUV2BGRA_UYVY = 112,
//COLOR_YUV2RGBA_VYUY = 113,
//COLOR_YUV2BGRA_VYUY = 114,
COLOR_YUV2RGBA_Y422 = COLOR_YUV2RGBA_UYVY,
COLOR_YUV2BGRA_Y422 = COLOR_YUV2BGRA_UYVY,
COLOR_YUV2RGBA_UYNV = COLOR_YUV2RGBA_UYVY,
COLOR_YUV2BGRA_UYNV = COLOR_YUV2BGRA_UYVY,
COLOR_YUV2RGB_YUY2 = 115,
COLOR_YUV2BGR_YUY2 = 116,
COLOR_YUV2RGB_YVYU = 117,
COLOR_YUV2BGR_YVYU = 118,
COLOR_YUV2RGB_YUYV = COLOR_YUV2RGB_YUY2,
COLOR_YUV2BGR_YUYV = COLOR_YUV2BGR_YUY2,
COLOR_YUV2RGB_YUNV = COLOR_YUV2RGB_YUY2,
COLOR_YUV2BGR_YUNV = COLOR_YUV2BGR_YUY2,
COLOR_YUV2RGBA_YUY2 = 119,
COLOR_YUV2BGRA_YUY2 = 120,
COLOR_YUV2RGBA_YVYU = 121,
COLOR_YUV2BGRA_YVYU = 122,
COLOR_YUV2RGBA_YUYV = COLOR_YUV2RGBA_YUY2,
COLOR_YUV2BGRA_YUYV = COLOR_YUV2BGRA_YUY2,
COLOR_YUV2RGBA_YUNV = COLOR_YUV2RGBA_YUY2,
COLOR_YUV2BGRA_YUNV = COLOR_YUV2BGRA_YUY2,
COLOR_YUV2GRAY_UYVY = 123,
COLOR_YUV2GRAY_YUY2 = 124,
//CV_YUV2GRAY_VYUY = CV_YUV2GRAY_UYVY,
COLOR_YUV2GRAY_Y422 = COLOR_YUV2GRAY_UYVY,
COLOR_YUV2GRAY_UYNV = COLOR_YUV2GRAY_UYVY,
COLOR_YUV2GRAY_YVYU = COLOR_YUV2GRAY_YUY2,
COLOR_YUV2GRAY_YUYV = COLOR_YUV2GRAY_YUY2,
COLOR_YUV2GRAY_YUNV = COLOR_YUV2GRAY_YUY2,
//! alpha premultiplication
COLOR_RGBA2mRGBA = 125,
COLOR_mRGBA2RGBA = 126,
//! RGB to YUV 4:2:0 family
COLOR_RGB2YUV_I420 = 127,
COLOR_BGR2YUV_I420 = 128,
COLOR_RGB2YUV_IYUV = COLOR_RGB2YUV_I420,
COLOR_BGR2YUV_IYUV = COLOR_BGR2YUV_I420,
COLOR_RGBA2YUV_I420 = 129,
COLOR_BGRA2YUV_I420 = 130,
COLOR_RGBA2YUV_IYUV = COLOR_RGBA2YUV_I420,
COLOR_BGRA2YUV_IYUV = COLOR_BGRA2YUV_I420,
COLOR_RGB2YUV_YV12 = 131,
COLOR_BGR2YUV_YV12 = 132,
COLOR_RGBA2YUV_YV12 = 133,
COLOR_BGRA2YUV_YV12 = 134,
//! Demosaicing
COLOR_BayerBG2BGR = 46,
COLOR_BayerGB2BGR = 47,
COLOR_BayerRG2BGR = 48,
COLOR_BayerGR2BGR = 49,
COLOR_BayerBG2RGB = COLOR_BayerRG2BGR,
COLOR_BayerGB2RGB = COLOR_BayerGR2BGR,
COLOR_BayerRG2RGB = COLOR_BayerBG2BGR,
COLOR_BayerGR2RGB = COLOR_BayerGB2BGR,
COLOR_BayerBG2GRAY = 86,
COLOR_BayerGB2GRAY = 87,
COLOR_BayerRG2GRAY = 88,
COLOR_BayerGR2GRAY = 89,
//! Demosaicing using Variable Number of Gradients
COLOR_BayerBG2BGR_VNG = 62,
COLOR_BayerGB2BGR_VNG = 63,
COLOR_BayerRG2BGR_VNG = 64,
COLOR_BayerGR2BGR_VNG = 65,
COLOR_BayerBG2RGB_VNG = COLOR_BayerRG2BGR_VNG,
COLOR_BayerGB2RGB_VNG = COLOR_BayerGR2BGR_VNG,
COLOR_BayerRG2RGB_VNG = COLOR_BayerBG2BGR_VNG,
COLOR_BayerGR2RGB_VNG = COLOR_BayerGB2BGR_VNG,
//! Edge-Aware Demosaicing
COLOR_BayerBG2BGR_EA = 135,
COLOR_BayerGB2BGR_EA = 136,
COLOR_BayerRG2BGR_EA = 137,
COLOR_BayerGR2BGR_EA = 138,
COLOR_BayerBG2RGB_EA = COLOR_BayerRG2BGR_EA,
COLOR_BayerGB2RGB_EA = COLOR_BayerGR2BGR_EA,
COLOR_BayerRG2RGB_EA = COLOR_BayerBG2BGR_EA,
COLOR_BayerGR2RGB_EA = COLOR_BayerGB2BGR_EA,
//! Demosaicing with alpha channel
COLOR_BayerBG2BGRA = 139,
COLOR_BayerGB2BGRA = 140,
COLOR_BayerRG2BGRA = 141,
COLOR_BayerGR2BGRA = 142,
COLOR_BayerBG2RGBA = COLOR_BayerRG2BGRA,
COLOR_BayerGB2RGBA = COLOR_BayerGR2BGRA,
COLOR_BayerRG2RGBA = COLOR_BayerBG2BGRA,
COLOR_BayerGR2RGBA = COLOR_BayerGB2BGRA,
COLOR_COLORCVT_MAX = 143
};
#endregion
#region 结构体
......@@ -47,7 +305,7 @@ namespace eyemLib_Sharp
[StructLayout(LayoutKind.Sequential)]
public struct EyemImage
{
public IntPtr ucpImage; // 地址
public IntPtr vpImage; // 地址
public int iWidth; // 图像内存 x 方向大小
public int iHeight; // 图像内存 y 方向大小
public int iDepth; // 图像位深度(详见说明)
......@@ -327,15 +585,30 @@ namespace eyemLib_Sharp
// Win32 memory copy function
[DllImport("ntdll.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern byte* memcpy(byte* dst, byte* src, int count);
//读取图像
//读取图像,支持彩色与多深度
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemImageRead(string filename, int iFalgs, out EyemImage tpImage);
//读取Raw格式图像,仅支持8/16位
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemImageReadRaw(string filename, int iWidth, int iHeight, int iDepth, out EyemImage tpImage);
//创建图像
//创建图像(uint8_t、int8_t、uint16_t、int16_t、int32_t、float_t、double_t)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemImageMalloc(int iWidth, int iHeight, int iChannels, string ccSubType, out EyemImage tpImage);
//图像颜色空间转换
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemImageMalloc(int iWidth, int iHeight, int iChannels, int iType, out EyemImage tpImage);
private static extern int eyemCvtImageColor(EyemImage tpImage, int iCCodes, ref EyemImage tpDstImg);
//图像数据格式转换
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCvtImageType(EyemImage tpImage, int rType, double alpha, double beta, ref EyemImage tpDstImg);
//显示图像
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemImageDisplay(string ccWinName, EyemImage tpImage);
//创建窗口
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemOpenWindow(string ccWinName);
//关闭窗口
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCloseWindow(string ccWinName);
//释放图像资源
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemImageFree(IntPtr ipImage);
......@@ -395,17 +668,15 @@ namespace eyemLib_Sharp
//findLine
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int iTransition, out MeasureHandle hObject);
//释放工具所使用句柄
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemEdge1dGenMeasureFree(IntPtr hObject);
#endregion
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemSkeleton(EyemImage tpImage);
//边缘
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemEdgesPixel(EyemImage tpImage, double dThresh);
//释放工具所使用句柄
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemEdge1dGenMeasureFree(IntPtr hObject);
#endregion
#region 稳健估计
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
......@@ -440,9 +711,15 @@ namespace eyemLib_Sharp
Console.WriteLine("读图失败!");
return;
}
int flags = eyemImageMalloc(ucpImage.iWidth, ucpImage.iHeight, 3, CV_16U, out tpDstImg);
//ucpImage.iWidth = 3072; ucpImage.iHeight = 3072; ucpImage.iDepth = 2;
eyemOpenWindow("eyemLib");
eyemImageDisplay("eyemLib", ucpImage);
//flag = eyemImageMalloc(ucpImage.iWidth, ucpImage.iHeight, 1, "uint8_t", out tpDstImg);
//flag = eyemCvtImageColor(ucpImage, (int)ColorConversionCodes.COLOR_BGR2RGB, ref tpDstImg);
//Bitmap bmp = new Bitmap(ucpImage.iWidth, ucpImage.iHeight, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
//ColorPalette color_palette_gray_ = bmp.Palette;
//for (int i = 0; i < 256; i++)
......@@ -451,7 +728,7 @@ namespace eyemLib_Sharp
//}
//bmp.Palette = color_palette_gray_;
//BitmapData bdd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
//memcpy((byte*)bdd.Scan0.ToPointer(), (byte*)ucpImage.ucpImage.ToPointer(), bdd.Stride * bdd.Height);
//memcpy((byte*)bdd.Scan0.ToPointer(), (byte*)ucpImage.vpImage.ToPointer(), bdd.Stride * bdd.Height);
//bmp.UnlockBits(bdd);
//bmp.Dispose();
......@@ -621,9 +898,11 @@ namespace eyemLib_Sharp
//sw.Stop();
//Console.WriteLine("耗时:" + sw.ElapsedMilliseconds.ToString() + ",结果:" + pNumObj);
//free image
eyemImageFree(ucpImage.ucpImage);
eyemImageFree(tpDstImg.vpImage);
eyemImageFree(ucpImage.vpImage);
}
//计算最佳参数
public static void eyemReadImageToolTest(string fileName)
{
......@@ -662,7 +941,7 @@ namespace eyemLib_Sharp
break;
}
//free image
eyemImageFree(ucpImage.ucpImage);
eyemImageFree(ucpImage.vpImage);
return;
}
......
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace eyemLib_Sharp
......@@ -19,9 +20,12 @@ namespace eyemLib_Sharp
// });
// Console.Write("请按任意键继续。。。");
//}
foreach (var fileName in fileNames)
{
EyemLib.eyemReadImageTool(fileName);
Thread.Sleep(1);
break;
}
Console.Write("请按任意键继续。。。");
Console.ReadKey();
......
......@@ -1244,7 +1244,7 @@ int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char *ccFileNam
//防止越界
for (int n = 0; n < 2; n++)
{
if (pt[n].x < 0) pt[n].x = 0.f; if (pt[n].x >= iX - 1) pt[n].x = float(iX - 1); if (pt[n].y < 0) pt[n].y = 0.f; if (pt[n].y >= iY - 1) pt[n].y = float(iY - 1);
if (pt[n].x < 0) pt[n].x = 0; if (pt[n].x >= iX - 1) pt[n].x = int(iX - 1); if (pt[n].y < 0) pt[n].y = 0; if (pt[n].y >= iY - 1) pt[n].y = int(iY - 1);
}
bool bFit = false;
//扫描像素密度,比例接近1:1记录下来,并且黑白间隔数目小大于长度的一半
......
......@@ -908,8 +908,7 @@ static int Yen(int hist[])
return threshold;
}
static double
getThreshVal_Otsu_8u(const cv::Mat& _src)
static double getThreshVal_Otsu_8u(const cv::Mat& _src)
{
cv::Size size = _src.size();
int step = (int)_src.step;
......
......@@ -8,6 +8,31 @@
#include "eyemLib.h"
// Chain code:
// 7 0 1
// 6 2
// 5 4 3
#define CV_CHAINCODE_UP 0 ///< Up.
#define CV_CHAINCODE_UP_RIGHT 1 ///< Up and right.
#define CV_CHAINCODE_RIGHT 2 ///< Right.
#define CV_CHAINCODE_DOWN_RIGHT 3 ///< Down and right.
#define CV_CHAINCODE_DOWN 4 ///< Down.
#define CV_CHAINCODE_DOWN_LEFT 5 ///< Down and left.
#define CV_CHAINCODE_LEFT 6 ///< Left.
#define CV_CHAINCODE_UP_LEFT 7 ///< Up and left.
const char movesE[4][3][4] = { { { -1, -1, 3, CV_CHAINCODE_UP_LEFT },{ 0, -1, 0, CV_CHAINCODE_UP },{ 1, -1, 0, CV_CHAINCODE_UP_RIGHT } },
{ { 1, -1, 0, CV_CHAINCODE_UP_RIGHT },{ 1, 0, 1, CV_CHAINCODE_RIGHT },{ 1, 1, 1, CV_CHAINCODE_DOWN_RIGHT } },
{ { 1, 1, 1, CV_CHAINCODE_DOWN_RIGHT },{ 0, 1, 2, CV_CHAINCODE_DOWN },{ -1, 1, 2, CV_CHAINCODE_DOWN_LEFT } },
{ { -1, 1, 2, CV_CHAINCODE_DOWN_LEFT },{ -1, 0, 3, CV_CHAINCODE_LEFT },{ -1, -1, 3, CV_CHAINCODE_UP_LEFT } }
};
const char movesI[4][3][4] = { { { 1, -1, 3, CV_CHAINCODE_UP_RIGHT },{ 0, -1, 0, CV_CHAINCODE_UP },{ -1, -1, 0, CV_CHAINCODE_UP_LEFT } },
{ { -1, -1, 0, CV_CHAINCODE_UP_LEFT },{ -1, 0, 1, CV_CHAINCODE_LEFT },{ -1, 1, 1, CV_CHAINCODE_DOWN_LEFT } },
{ { -1, 1, 1, CV_CHAINCODE_DOWN_LEFT },{ 0, 1, 2, CV_CHAINCODE_DOWN },{ 1, 1, 2, CV_CHAINCODE_DOWN_RIGHT } },
{ { 1, 1, 2, CV_CHAINCODE_DOWN_RIGHT },{ 1, 0, 3, CV_CHAINCODE_RIGHT },{ 1, -1, 3, CV_CHAINCODE_UP_RIGHT } }
};
typedef unsigned int CvLabel;
const char cvChainCodeMoves[8][2] = {
......
......@@ -103,7 +103,7 @@ int eyemEdge1dGenMeasureRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY
cv::Mat filter, diffMat, one;
diffMat = convert(rotImg(roi), CV_64F);
diffMat = /*convert(rotImg(roi), CV_64F)*/cv::Mat();
//计算投影
cv::reduce(diffMat, one, 0, cv::REDUCE_AVG, CV_64F);
......@@ -282,7 +282,8 @@ int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLi
cv::Mat F, G;
F = convert(rotImg(roi), CV_64F);
//TODO:增加处理接口
F = /*convert(rotImg(roi), CV_64F)*/cv::Mat();
//高斯滤波
cv::GaussianBlur(F, G, cv::Size(3, 3), dSigma, dSigma);
......@@ -332,7 +333,7 @@ int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLi
cv::Mat showMat3;
cv::cvtColor(convert(F, CV_8U), showMat3, cv::COLOR_GRAY2BGR);
cv::cvtColor(/*convert(F, CV_8U)*/cv::Mat(), showMat3, cv::COLOR_GRAY2BGR);
EyemOcsDXY tpEdge;
std::vector<EyemOcsDXY> *tpEdges = new std::vector<EyemOcsDXY>();
......@@ -435,7 +436,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
cv::cvtColor(image, cc, cv::COLOR_GRAY2BGR);
for (int i = 0; i < 31; i++)
{
cc.at<cv::Vec3b>(cv::Point2f(map1.at<double>(0, i), map2.at<double>(0, i))) = cv::Vec3b(0, 255, 0);
cc.at<cv::Vec3b>(cv::Point(cvRound(map1.at<double>(0, i)), cvRound(map2.at<double>(0, i)))) = cv::Vec3b(0, 255, 0);
}
return FUNC_OK;
......
#include "eyemGeneric.h"
cv::Mat convert(cv::Mat& src, const int depth)
int eyemImageRead(const char *filename, int iFlag, EyemImage *tpImage)
{
cv::Mat ret;
src.convertTo(ret, depth);
return ret;
cv::Mat src = cv::imread(filename, iFlag);
if (src.empty())
return FUNC_IMAGE_NOT_EXIST;
//图像信息
tpImage->iWidth = src.cols; tpImage->iHeight = src.rows; tpImage->iDepth = src.depth(); tpImage->iChannels = src.channels();
//内存尺寸
int _Size = tpImage->iWidth*tpImage->iHeight*tpImage->iChannels;
switch (tpImage->iDepth)
{
case CV_8U:
_Size *= sizeof(uint8_t);
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);
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);
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);
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);
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);
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);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
default:
//no support format
return FUNC_CANNOT_USE;
}
//拷贝数据
memcpy(tpImage->vpImage, src.data, _Size);
return FUNC_OK;
}
int eyemImageMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType, EyemImage *tpImage)
{
//图像信息
tpImage->iWidth = iWidth; tpImage->iHeight = iHeight; tpImage->iChannels = 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);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
}
else if (strcmp(ccSubType, "int8_t") == 0) {
tpImage->iDepth = 1;
_Size *= sizeof(int8_t);
tpImage->vpImage = (int8_t *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
}
else if (strcmp(ccSubType, "uint16_t") == 0) {
tpImage->iDepth = 2;
_Size *= sizeof(uint16_t);
tpImage->vpImage = (uint16_t *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
}
else if (strcmp(ccSubType, "int16_t") == 0) {
tpImage->iDepth = 3;
_Size *= sizeof(int16_t);
tpImage->vpImage = (int16_t *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
}
else if (strcmp(ccSubType, "int32_t") == 0) {
tpImage->iDepth = 4;
_Size *= sizeof(int32_t);
tpImage->vpImage = (int32_t *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
}
else if (strcmp(ccSubType, "float_t") == 0) {
tpImage->iDepth = 5;
_Size *= sizeof(float_t);
tpImage->vpImage = (float_t *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
}
else if (strcmp(ccSubType, "double_t") == 0) {
tpImage->iDepth = 6;
_Size *= sizeof(double_t);
tpImage->vpImage = (double_t *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
}
else {//no support format
return FUNC_CANNOT_USE;
}
return FUNC_OK;
}
void spatialGradient(cv::Mat src, cv::Mat &dx, cv::Mat &dy)
int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, EyemImage *tpImage)
{
if (std::strlen(filename) == 0)
return FUNC_IMAGE_NOT_EXIST;
FILE *fp = fopen(filename, "rb+");
if (NULL != fp)
{
switch (iDepth)
{
case CV_8U:
tpImage->vpImage = (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);
break;
case CV_16U:
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);
break;
default:
//不支持位深度
break;
}
}
else
return FUNC_IMAGE_NOT_EXIST;
return FUNC_OK;
}
int eyemCvtImageType(EyemImage tpImage, int rType, double alpha, double beta, EyemImage &tpDstImg)
{
CV_Assert(NULL != tpImage.vpImage);
//图像信息
if (NULL == tpDstImg.vpImage) {
}
return FUNC_OK;
}
int eyemCvtImageColor(EyemImage tpImage, int iCCodes, EyemImage &tpDstImg)
{
CV_Assert(NULL != tpImage.vpImage);
//颜色空间转换
cv::Mat _dst;
cv::cvtColor(cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage), \
_dst, iCCodes);
//如果预先分配了内存,则判断基本信息是否符合
if (NULL != tpDstImg.vpImage)
CV_Assert(_dst.cols == tpDstImg.iWidth && _dst.rows == tpDstImg.iHeight && _dst.depth() == tpDstImg.iDepth && _dst.channels() == tpDstImg.iChannels);
//内存尺寸
int _Size = tpImage.iWidth *tpImage.iHeight *_dst.channels();
//不存在则创建
if (NULL == tpDstImg.vpImage) {
//目标图像信息
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);
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_CANNOT_USE;
}
}
//拷贝数据
memcpy(tpDstImg.vpImage, _dst.data, _Size);
return FUNC_OK;
}
int eyemImageAdd(EyemImage tpImageA, EyemImage tpImageB, EyemImage &tpDstImg)
{
CV_Assert((NULL != tpImageA.vpImage) && (NULL != tpImageB.vpImage));
CV_Assert(tpImageA.iWidth == tpImageB.iWidth&&tpImageA.iHeight == tpImageB.iHeight&&tpImageA.iDepth == tpImageB.iDepth&&tpImageA.iChannels == tpImageB.iChannels);
cv::Mat _dst;
cv::add(cv::Mat(tpImageA.iHeight, tpImageA.iWidth, MAKETYPE(tpImageA.iDepth, tpImageA.iChannels), tpImageA.vpImage), \
cv::Mat(tpImageB.iHeight, tpImageB.iWidth, MAKETYPE(tpImageB.iDepth, tpImageB.iChannels), tpImageB.vpImage), _dst);
//如果预先分配了内存,则判断基本信息是否符合
if (NULL != tpDstImg.vpImage)
CV_Assert(_dst.cols == tpDstImg.iWidth && _dst.rows == tpDstImg.iHeight && _dst.depth() == tpDstImg.iDepth && _dst.channels() == tpDstImg.iChannels);
//内存尺寸
int _Size = _dst.cols *_dst.rows *_dst.channels();
//不存在则创建
if (NULL == tpDstImg.vpImage) {
//目标图像信息
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);
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_CANNOT_USE;
}
}
//拷贝数据
memcpy(tpDstImg.vpImage, _dst.data, _Size);
return FUNC_OK;
}
int eyemImageSub(EyemImage tpImageA, EyemImage tpImageB, EyemImage &tpDstImg)
{
CV_Assert((NULL != tpImageA.vpImage) && (NULL != tpImageB.vpImage));
CV_Assert(tpImageA.iWidth == tpImageB.iWidth&&tpImageA.iHeight == tpImageB.iHeight&&tpImageA.iDepth == tpImageB.iDepth&&tpImageA.iChannels == tpImageB.iChannels);
cv::Mat _dst;
cv::subtract(cv::Mat(tpImageA.iHeight, tpImageA.iWidth, MAKETYPE(tpImageA.iDepth, tpImageA.iChannels), tpImageA.vpImage), \
cv::Mat(tpImageB.iHeight, tpImageB.iWidth, MAKETYPE(tpImageB.iDepth, tpImageB.iChannels), tpImageB.vpImage), _dst);
//如果预先分配了内存,则判断基本信息是否符合
if (NULL != tpDstImg.vpImage)
CV_Assert(_dst.cols == tpDstImg.iWidth && _dst.rows == tpDstImg.iHeight && _dst.depth() == tpDstImg.iDepth && _dst.channels() == tpDstImg.iChannels);
//内存尺寸
int _Size = _dst.cols *_dst.rows *_dst.channels();
//不存在则创建
if (NULL == tpDstImg.vpImage) {
//目标图像信息
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);
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_CANNOT_USE;
}
}
//拷贝数据
memcpy(tpDstImg.vpImage, _dst.data, _Size);
return FUNC_OK;
}
int eyemImageAbs(EyemImage tpImage, EyemImage &tpDstImg)
{
CV_Assert((NULL != tpImage.vpImage));
cv::Mat _dst = cv::abs(cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage));
//如果预先分配了内存,则判断基本信息是否符合
if (NULL != tpDstImg.vpImage)
CV_Assert(_dst.cols == tpDstImg.iWidth && _dst.rows == tpDstImg.iHeight && _dst.depth() == tpDstImg.iDepth && _dst.channels() == tpDstImg.iChannels);
//内存尺寸
int _Size = _dst.cols *_dst.rows *_dst.channels();
//不存在则创建
if (NULL == tpDstImg.vpImage) {
//目标图像信息
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);
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_CANNOT_USE;
}
}
//拷贝数据
memcpy(tpDstImg.vpImage, _dst.data, _Size);
return FUNC_OK;
}
void eyemImageDisplay(const char *ccWinName, EyemImage tpImage)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage);
cv::imshow(ccWinName, src);
cv::waitKey(1);
}
void eyemOpenWindow(const char *ccWinName)
{
cv::namedWindow(ccWinName, cv::WINDOW_AUTOSIZE);
}
void eyemCloseWindow(const char *ccWinName)
{
cv::destroyWindow(ccWinName);
}
void eyemImageFree(void *vpImage)
{
cv::Sobel(src, dx, src.depth(), 1, 0);
cv::Sobel(src, dy, src.depth(), 0, 1);
//must be free 空指针也没关系
free(vpImage);
}
\ No newline at end of file
......@@ -9,8 +9,4 @@
cv::Mat convert(cv::Mat &src, const int depth);
void spatialGradient(cv::Mat src, cv::Mat &dx, cv::Mat &dy);
#endif/* __EYEM_GENERIC_H */
\ No newline at end of file
......@@ -7,6 +7,7 @@
#include <Windows.h>
#include <opencv.hpp>
#include <opencv2\opencv.hpp>
#ifndef EXPORTS
......@@ -578,30 +579,6 @@ enum
BINARIZATION_SAUVOLA
};
// Chain code:
// 7 0 1
// 6 2
// 5 4 3
#define CV_CHAINCODE_UP 0 ///< Up.
#define CV_CHAINCODE_UP_RIGHT 1 ///< Up and right.
#define CV_CHAINCODE_RIGHT 2 ///< Right.
#define CV_CHAINCODE_DOWN_RIGHT 3 ///< Down and right.
#define CV_CHAINCODE_DOWN 4 ///< Down.
#define CV_CHAINCODE_DOWN_LEFT 5 ///< Down and left.
#define CV_CHAINCODE_LEFT 6 ///< Left.
#define CV_CHAINCODE_UP_LEFT 7 ///< Up and left.
const char movesE[4][3][4] = { { { -1, -1, 3, CV_CHAINCODE_UP_LEFT },{ 0, -1, 0, CV_CHAINCODE_UP },{ 1, -1, 0, CV_CHAINCODE_UP_RIGHT } },
{ { 1, -1, 0, CV_CHAINCODE_UP_RIGHT },{ 1, 0, 1, CV_CHAINCODE_RIGHT },{ 1, 1, 1, CV_CHAINCODE_DOWN_RIGHT } },
{ { 1, 1, 1, CV_CHAINCODE_DOWN_RIGHT },{ 0, 1, 2, CV_CHAINCODE_DOWN },{ -1, 1, 2, CV_CHAINCODE_DOWN_LEFT } },
{ { -1, 1, 2, CV_CHAINCODE_DOWN_LEFT },{ -1, 0, 3, CV_CHAINCODE_LEFT },{ -1, -1, 3, CV_CHAINCODE_UP_LEFT } }
};
const char movesI[4][3][4] = { { { 1, -1, 3, CV_CHAINCODE_UP_RIGHT },{ 0, -1, 0, CV_CHAINCODE_UP },{ -1, -1, 0, CV_CHAINCODE_UP_LEFT } },
{ { -1, -1, 0, CV_CHAINCODE_UP_LEFT },{ -1, 0, 1, CV_CHAINCODE_LEFT },{ -1, 1, 1, CV_CHAINCODE_DOWN_LEFT } },
{ { -1, 1, 1, CV_CHAINCODE_DOWN_LEFT },{ 0, 1, 2, CV_CHAINCODE_DOWN },{ 1, 1, 2, CV_CHAINCODE_DOWN_RIGHT } },
{ { 1, 1, 2, CV_CHAINCODE_DOWN_RIGHT },{ 1, 0, 3, CV_CHAINCODE_RIGHT },{ 1, -1, 3, CV_CHAINCODE_UP_RIGHT } }
};
// Blob 分析结果
typedef struct {
......@@ -797,6 +774,32 @@ extern "C" {
//////////////////////////////////////////////////////////////////////////////////////////////
// 图像通用处理(eyemGeneric.cpp)
//
#ifdef __cplusplus
extern "C" {
#endif
// 函数接口
EXPORTS int eyemImageRead(const char *filename, int iFalgs, EyemImage *ucpImage);
EXPORTS int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, EyemImage *tpImage);
EXPORTS int eyemImageMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType, EyemImage *tpImage);
EXPORTS int eyemCvtImageColor(EyemImage tpImage, int iCCodes, EyemImage &tpDstImg);
EXPORTS int eyemCvtImageType(EyemImage tpImage, int rType, double alpha, double beta, EyemImage &tpDstImg);
EXPORTS int eyemImageAdd(EyemImage tpImageA, EyemImage tpImageB, EyemImage &tpImage);
EXPORTS int eyemImageSub(EyemImage tpImageA, EyemImage tpImageB, EyemImage &tpImage);
EXPORTS int eyemImageAbs(EyemImage tpImageA, EyemImage tpImageB, EyemImage &tpImage);
EXPORTS void eyemImageDisplay(const char *ccWinName, EyemImage tpImage);
EXPORTS void eyemOpenWindow(const char *ccWinName);
EXPORTS void eyemCloseWindow(const char *ccWinName);
EXPORTS void eyemImageFree(void *ipImage);
#ifdef __cplusplus
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////
// 其他工具(eyemMisc.cpp)
//
......@@ -817,10 +820,6 @@ extern "C" {
EXPORTS bool eyemDetectAndDecodeFree(IntPtr hObject);
EXPORTS int eyemCountObject(EyemImage tpImage, const char *fileName, double dOffset, int iMinArea, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, double dOffset, const char * ccSubType, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg);
EXPORTS int eyemImageRead(const char *filename, int iFalgs, EyemImage *ucpImage);
EXPORTS int eyemImageMalloc(int iWidth, int iHeight, int iChannels, int ccType, EyemImage *tpImage);
EXPORTS int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, EyemImage *tpImage);
EXPORTS void eyemImageFree(void *ipImage);
#ifdef __cplusplus
}
......
#include "eyemMisc.h"
int eyemImageRead(const char *filename, int iFlag, EyemImage *tpImage)
{
cv::Mat src = cv::imread(filename, iFlag);
if (src.empty())
return FUNC_IMAGE_NOT_EXIST;
//图像信息
int _X = src.cols, _Y = src.rows, _Depth = src.depth(), _Channels = src.channels();
//内存尺寸
int _Size = _X*_Y*_Channels;
switch (src.depth())
{
case CV_8U:
_Size *= sizeof(unsigned char);
tpImage->vpImage = (unsigned char *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_8S:
_Size *= sizeof(signed char);
tpImage->vpImage = (signed char *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_16U:
_Size *= sizeof(unsigned short);
tpImage->vpImage = (unsigned short *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_16S:
_Size *= sizeof(signed short);
tpImage->vpImage = (signed short *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_32S:
_Size *= sizeof(signed int);
tpImage->vpImage = (signed int *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_32F:
_Size *= sizeof(float);
tpImage->vpImage = (float *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_64F:
_Size *= sizeof(double);
tpImage->vpImage = (double *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
default:
//no support format
return FUNC_CANNOT_USE;
}
//图像信息
tpImage->iWidth = _X; tpImage->iHeight = _Y; tpImage->iDepth = _Depth; tpImage->iChannels = _Channels;
//拷贝数据
memcpy(tpImage->vpImage, src.data, _Size);
return FUNC_OK;
}
int eyemImageMalloc(int iWidth, int iHeight, int iChannels, int ccType, EyemImage *tpImage)
{
//内存尺寸
int _Size = iWidth*iHeight*iChannels;
switch (ccType)
{
case CV_8U:
tpImage->iDepth = 0;
_Size *= sizeof(unsigned char);
tpImage->vpImage = (unsigned char *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_8S:
tpImage->iDepth = 1;
_Size *= sizeof(signed char);
tpImage->vpImage = (signed char *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_16U:
tpImage->iDepth = 2;
_Size *= sizeof(unsigned short);
tpImage->vpImage = (unsigned short *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_16S:
tpImage->iDepth = 3;
_Size *= sizeof(signed short);
tpImage->vpImage = (signed short *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_32S:
tpImage->iDepth = 4;
_Size *= sizeof(signed int);
tpImage->vpImage = (signed int *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_32F:
tpImage->iDepth = 5;
_Size *= sizeof(float);
tpImage->vpImage = (float *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
case CV_64F:
tpImage->iDepth = 6;
_Size *= sizeof(double);
tpImage->vpImage = (double *)malloc(_Size);
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, _Size);
break;
default:
//no support format
return FUNC_CANNOT_USE;
}
//图像信息
tpImage->iWidth = iWidth; tpImage->iHeight = iHeight; tpImage->iChannels = iChannels;
return FUNC_OK;
}
int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, EyemImage *tpImage)
{
if (std::strlen(filename) == 0)
return FUNC_IMAGE_NOT_EXIST;
FILE *fp = fopen(filename, "rb+");
if (NULL != fp)
{
switch (iDepth)
{
case CV_8U:
tpImage->vpImage = (unsigned char *)malloc(iWidth*iHeight * sizeof(unsigned char));
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, iWidth*iHeight * sizeof(unsigned char));
fread(tpImage->vpImage, sizeof(unsigned char), iWidth*iHeight, fp);
break;
case CV_16U:
tpImage->vpImage = (unsigned short *)malloc(iWidth*iHeight * sizeof(unsigned short));
if (NULL == tpImage->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpImage->vpImage, 0, iWidth*iHeight * sizeof(unsigned short));
fread(tpImage->vpImage, sizeof(unsigned short), iWidth*iHeight, fp);
break;
default:
//不支持位深度
break;
}
}
else
return FUNC_IMAGE_NOT_EXIST;
return FUNC_OK;
}
static void drawLine(cv::InputOutputArray img, cv::Point pt1, cv::Point pt2, const cv::Scalar& color, int thickness, double tipLength, double trackLength, std::vector<cv::Point> &trackLine)
{
const double angle = atan2((double)pt1.y - pt2.y, (double)pt1.x - pt2.x);
......@@ -2909,8 +2733,4 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, doubl
return FUNC_OK;
}
void eyemImageFree(void *ucpImage)
{
// must be free
free(ucpImage);
}
......@@ -5,7 +5,6 @@
#ifndef __EYEM_MISC_H
#define __EYEM_MISC_H
#include <omp.h>
#include <io.h>
#include <direct.h>
#include "eyemLib.h"
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!