1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| static Mat ToMat(Bitmap^ bitmap) {
return Mat(ToIpl(bitmap));
}
static IplImage* ToIpl(Bitmap^ bitmap) {
auto format = PixelFormat::Format32bppArgb;
auto size = cvSize(bitmap->Width, bitmap->Height);
int depth = 8;
int channel = 4;
if (bitmap == nullptr) return 0;
if (bitmap->PixelFormat != format) return 0;
IplImage* ipl = cvCreateImage(size, depth, channel);
BitmapData^ data = bitmap->LockBits(
Drawing::Rectangle(0, 0, bitmap->Width, bitmap->Height),
ImageLockMode::ReadWrite,
format
);
memcpy_s(ipl->imageData, ipl->widthStep * ipl->height,
data->Scan0.ToPointer(), data->Stride * data->Height
);
return (ipl);
}
|