复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70//转Halcon图像 HObject ImageDataPtr2HObject(CCameraDS& CameraDS, BYTE* imageDataPtr) { HObject image; if (8 == CameraDS.GetBitCount()) //灰度图 { //造一个灰度图 GenImage1( &image, "byte", CameraDS.GetWidth(), CameraDS.GetHeight(), Hlong(imageDataPtr) ); } else { BYTE* RChannel = NULL, * GChannel = NULL, * BChannel = NULL; int Width, Height; Width = CameraDS.GetWidth(); Height = CameraDS.GetHeight(); RChannel = new BYTE[Width * Height]; GChannel = new BYTE[Width * Height]; BChannel = new BYTE[Width * Height]; //4字节对齐 int LineByte = (Width * CameraDS.GetBitCount() + 31) / 32 * 4; for (int i = 0; i < Height; i++) //图像的高---行 { for (int j = 0; j < Width; j++) //图像的宽---列 { //图像效果上下左右镜像 顺序读取时 /*memcpy(BChannel + Width * i + j, imageDataPtr + LineByte * i + 3 * j + 0, 1); memcpy(GChannel + Width * i + j, imageDataPtr + LineByte * i + 3 * j + 1, 1); memcpy(RChannel + Width * i + j, imageDataPtr + LineByte * i + 3 * j + 2, 1);*/ //使上下翻转 memcpy(BChannel + Width * (Height - 1 - i) + j, imageDataPtr + LineByte * i + 3 * j + 0, 1); memcpy(GChannel + Width * (Height - 1 - i) + j, imageDataPtr + LineByte * i + 3 * j + 1, 1); memcpy(RChannel + Width * (Height - 1 - i) + j, imageDataPtr + LineByte * i + 3 * j + 2, 1); //使左右翻转 /*memcpy(BChannel + Width * i + Width - 1 - j , imageDataPtr + LineByte * i + 3 * j + 0, 1); memcpy(GChannel + Width * i + Width - 1 - j, imageDataPtr + LineByte * i + 3 * j + 1, 1); memcpy(RChannel + Width * i + Width - 1 - j, imageDataPtr + LineByte * i + 3 * j + 2, 1);*/ //使上下左右翻转 /*memcpy(BChannel + Width * (Height - 1 - i) + Width - 1 - j, imageDataPtr + LineByte * i + 3 * j + 0, 1); memcpy(GChannel + Width * (Height - 1 - i) + Width - 1 - j, imageDataPtr + LineByte * i + 3 * j + 1, 1); memcpy(RChannel + Width * (Height - 1 - i) + Width - 1 - j, imageDataPtr + LineByte * i + 3 * j + 2, 1);*/ //参考 /*memcpy(BChannel + Width * i + Width - j - 1, imageDataPtr + LineByte * (Height - 1 - i) + 3 * (Width - 1 - j) + 0, 1); memcpy(GChannel + Width * i + Width - j - 1, imageDataPtr + LineByte * (Height - 1 - i) + 3 * (Width - 1 - j) + 1, 1); memcpy(RChannel + Width * i + Width - j - 1, imageDataPtr + LineByte * (Height - 1 - i) + 3 * (Width - 1 - j) + 2, 1);*/ } } //创建3通道图像 GenImage3( &image, "byte", Width, Height, Hlong(RChannel), Hlong(GChannel), Hlong(BChannel) ); delete[] RChannel; delete[] GChannel; delete[] BChannel; } return image; }
最后
以上就是舒适自行车最近收集整理的关于用DirectShow调用摄像头采集图像并转化为halcon图像的全部内容,更多相关用DirectShow调用摄像头采集图像并转化为halcon图像内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复