vc++ 代码
bool Recognize(Point_2F *arr,uchar* b) { Mat src=cv::Mat(415,770,CV_8UC3,b); /*for (int i=0;i<src.rows;i++) { memcpy(src.ptr(i),b+i*src.cols,src.cols); }*/ cv::imwrite("D:\\my_2_testfiles\\111_before.png",src); // 保存的照片和原来的照片不一样而且大小也不一样? }
C#代码
[DllImport("rectanglepoints.dll", EntryPoint = "Recognize", CallingConvention = CallingConvention.Cdecl)] static extern byte Recognize(IntPtr arr, IntPtr b);
{ // Create a new bitmap. Bitmap bmp = new Bitmap("D:\\my_2_testfiles\\111.png"); // Lock the bitmap's bits. Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); // Get the address of the first line. IntPtr ptrImg = bmpData.Scan0; bool ret; ret = Convert.ToBoolean(Recognize(IntPtr.Zero, ptrImg)); // Unlock the bits. bmp.UnlockBits(bmpData); Console.Read(); }
照片附加
原图:
调用vc++ dll后保存的图片
每行有padding缘故
每行第像素第字节对齐4字节边界上(无法理解句理解每行第像素第字节地址被4整除)
opencv没有做把padding也当作有效数据会偏
你好,请问你的问题最后是和解决的呢,可否将代码贴出来