|
1 |
| -# 相机文档 |
2 |
| ---- |
3 |
| - |
4 |
| -### 相机程序逻辑 |
5 |
| - |
6 |
| - |
7 |
| -- 运行相机程序,会出现相机程序的gui,如图: |
8 |
| - |
9 |
| - |
10 |
| - |
11 |
| -- **Recording count**变量的框设置为数值1,因为我们每次只需拍一张图片,用作python程序的输入来处理图片。 |
12 |
| - |
13 |
| -- 点击**Start**开始拍照,拍照的流程如下: |
14 |
| - - 判断是否启动相机实例,只有存在实例的情况下进入`while`循环,进行照片的获取、记录和保存。 |
15 |
| - - 在`while`循环中,首先判断相机是否已经在记录当中且已经记录了至少一张图片,如果为真的话则停止记录,清除缓存,再打开相机记录;为假的话则直接打开相机记录。 |
16 |
| - - 接着延迟200ms,处理所有的当前在消息队列中的Windows消息。 |
17 |
| - - 再次判断相机是否已经在记录或者至少记录了一张图片,为真时进入以下流程:从缓冲区获取已记录的照片的列表,将照片保留,清除缓存,释放已分配内存。 |
18 |
| - - 接着再一次停止记录,关掉图片获取,打开图片获取(此时已执行完`while`循环内的内容)。 |
19 |
| - |
20 |
| -- 由于每次存的图片命名是相同的,每次新图片会强制覆盖旧图片,而机械臂收回到相机范围外停留时间远大于每次拍照时间,所以python处理的最新图片不会有机械臂的影响 |
21 |
| - |
22 |
| - |
23 |
| - |
24 |
| - |
25 |
| - |
26 |
| - |
27 |
| -```cs |
28 |
| -private void startCaptureButton_Click(object sender, EventArgs e); |
29 |
| -``` |
30 |
| -这个函数是相机gui里**Start**按钮对应的事件函数,也是我们需要点击操作来启动相机程序。当启动相机程序后,就不需要对其进行任何操作了。 |
31 |
| - |
32 |
| -`StartAsyncImageRecording` 开始图片记录的函数 |
33 |
| - |
34 |
| -`StartImageAcquisition` 开始图片获取的函数(调用后并未写入内存) |
35 |
| - |
36 |
| -`StopAcquisition` 停止获取图片的函数 |
37 |
| - |
38 |
| -### 核心代码 |
39 |
| - |
40 |
| -```cs |
41 |
| - private void startCaptureButton_Click(object sender, EventArgs e) |
42 |
| - { |
43 |
| - while (myCamera != null) |
44 |
| - { |
45 |
| - if (myCamera.IsAsyncImageRecordingRunning || (myCamera.TotalAsyncImagesRecordedCount > 0)) |
46 |
| - { |
47 |
| - myCamera.StopAsyncImageRecording(); |
48 |
| - myCamera.FreeAsyncRecordedImages(); |
49 |
| - myCamera.StartAsyncImageRecording(Convert.ToInt32(captureCountNumericUpDown.Value), (CCamera.AsyncImageRecordingMode)recordingModeComboBox.SelectedIndex, Convert.ToInt32(skipCountNumericUpDown.Value)); |
50 |
| - } |
51 |
| - else |
52 |
| - { |
53 |
| - myCamera.StartAsyncImageRecording(Convert.ToInt32(captureCountNumericUpDown.Value), (CCamera.AsyncImageRecordingMode)recordingModeComboBox.SelectedIndex, Convert.ToInt32(skipCountNumericUpDown.Value)); |
54 |
| - } |
55 |
| - |
56 |
| - Delay(200); |
57 |
| - |
58 |
| - Application.DoEvents(); |
59 |
| - if (!myCamera.IsAsyncImageRecordingRunning && (myCamera.TotalAsyncImagesRecordedCount > 0)) |
60 |
| - { |
61 |
| - // Prompt the user if he wants to continue or not with the image save |
62 |
| - // if (MessageBox.Show(this, "Image save might take long time!\nAre you sure you want to continue?", "Image Save", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK) |
63 |
| - // { |
64 |
| - // Disable the Image Recording buttons as long as we are saving the images |
65 |
| - //asynchImageRecordingGroupBox.Enabled = false; |
66 |
| -
|
67 |
| - // Get the recorded images as a list |
68 |
| - List<Jai_FactoryWrapper.ImageInfo> imageList = myCamera.GetAsyncRecordedImages(); |
69 |
| - |
70 |
| - // Any images recorded? |
71 |
| -
|
72 |
| - if (imageList != null && (imageList.Count > 0)) |
73 |
| - { |
74 |
| - // Run through the list of recorded images |
75 |
| - int index = myCamera.TotalAsyncImagesRecordedCount - 1; |
76 |
| - Jai_FactoryWrapper.EFactoryError error = Jai_FactoryWrapper.EFactoryError.Success; |
77 |
| - |
78 |
| - // Get the recorded image at this index |
79 |
| - Jai_FactoryWrapper.ImageInfo ii = imageList[index]; |
80 |
| - |
81 |
| - // Are we saving the images in "raw" format or in Tiff? |
82 |
| -
|
83 |
| - // Create local image that will contain the converted image |
84 |
| - Jai_FactoryWrapper.ImageInfo localImageInfo = new Jai_FactoryWrapper.ImageInfo(); |
85 |
| - |
86 |
| - // Allocate buffer that will contain the converted image |
87 |
| - // In this sample we re-allocate the buffer over-and-over because we assume that the recorded images could be |
88 |
| - // of different size (If we have been using the Sequence functionality in the cameras) |
89 |
| - error = Jai_FactoryWrapper.J_Image_Malloc(ref ii, ref localImageInfo); |
90 |
| - |
91 |
| - // Convert the raw image to image format |
92 |
| - error = Jai_FactoryWrapper.J_Image_FromRawToImage(ref ii, ref localImageInfo, 4096, 4096, 4096); |
93 |
| - |
94 |
| - // Save the image to disks |
95 |
| - error = Jai_FactoryWrapper.J_Image_SaveFile(ref localImageInfo, "..\\" + "phone.png"); |
96 |
| - |
97 |
| - //error = Jai_FactoryWrapper.J_Image_SaveFile(ref localImageInfo, "C:\\Users\\aida\\Desktop\\wechat_jump\\" + "phone.png"); |
98 |
| -
|
99 |
| - //Free the conversion buffer |
100 |
| - error = Jai_FactoryWrapper.J_Image_Free(ref localImageInfo); |
101 |
| - |
102 |
| - Application.DoEvents(); |
103 |
| - |
104 |
| - } |
105 |
| - myCamera.StopAsyncImageRecording(); |
106 |
| - myCamera.StopImageAcquisition(); |
107 |
| - myCamera.StartImageAcquisition(true, 5); |
108 |
| - |
109 |
| - // Re-enable the Image Recording buttons |
110 |
| - //asynchImageRecordingGroupBox.Enabled = true; |
111 |
| - //} |
112 |
| - } |
113 |
| - } |
114 |
| - } |
| 1 | +# 相机文档 |
| 2 | +--- |
| 3 | + |
| 4 | +### 相机程序逻辑 |
| 5 | + |
| 6 | + |
| 7 | +- 运行相机程序,会出现相机程序的gui,如图: |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +- **Recording count**变量的框设置为数值1,因为我们每次只需拍一张图片,用作python程序的输入来处理图片。 |
| 12 | + |
| 13 | +- 点击**Start**开始拍照,拍照的流程如下: |
| 14 | + - 判断是否启动相机实例,只有存在实例的情况下进入`while`循环,进行照片的获取、记录和保存。 |
| 15 | + - 在`while`循环中,首先判断相机是否已经在记录当中且已经记录了至少一张图片,如果为真的话则停止记录,清除缓存,再打开相机记录;为假的话则直接打开相机记录。 |
| 16 | + - 接着延迟200ms,处理所有的当前在消息队列中的Windows消息。 |
| 17 | + - 再次判断相机是否已经在记录或者至少记录了一张图片,为真时进入以下流程:从缓冲区获取已记录的照片的列表,将照片保留,清除缓存,释放已分配内存。 |
| 18 | + - 接着再一次停止记录,关掉图片获取,打开图片获取(此时已执行完`while`循环内的内容)。 |
| 19 | + |
| 20 | +- 由于每次存的图片命名是相同的,每次新图片会强制覆盖旧图片,而机械臂收回到相机范围外停留时间远大于每次拍照时间,所以python处理的最新图片不会有机械臂的影响 |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +```cs |
| 28 | +private void startCaptureButton_Click(object sender, EventArgs e); |
| 29 | +``` |
| 30 | +这个函数是相机gui里**Start**按钮对应的事件函数,也是我们需要点击操作来启动相机程序。当启动相机程序后,就不需要对其进行任何操作了。 |
| 31 | + |
| 32 | +`StartAsyncImageRecording` 开始图片记录的函数 |
| 33 | + |
| 34 | +`StartImageAcquisition` 开始图片获取的函数(调用后并未写入内存) |
| 35 | + |
| 36 | +`StopAcquisition` 停止获取图片的函数 |
| 37 | + |
| 38 | +### 核心代码 |
| 39 | + |
| 40 | +```cs |
| 41 | + private void startCaptureButton_Click(object sender, EventArgs e) |
| 42 | + { |
| 43 | + while (myCamera != null) |
| 44 | + { |
| 45 | + if (myCamera.IsAsyncImageRecordingRunning || (myCamera.TotalAsyncImagesRecordedCount > 0)) |
| 46 | + { |
| 47 | + myCamera.StopAsyncImageRecording(); |
| 48 | + myCamera.FreeAsyncRecordedImages(); |
| 49 | + myCamera.StartAsyncImageRecording(Convert.ToInt32(captureCountNumericUpDown.Value), (CCamera.AsyncImageRecordingMode)recordingModeComboBox.SelectedIndex, Convert.ToInt32(skipCountNumericUpDown.Value)); |
| 50 | + } |
| 51 | + else |
| 52 | + { |
| 53 | + myCamera.StartAsyncImageRecording(Convert.ToInt32(captureCountNumericUpDown.Value), (CCamera.AsyncImageRecordingMode)recordingModeComboBox.SelectedIndex, Convert.ToInt32(skipCountNumericUpDown.Value)); |
| 54 | + } |
| 55 | + |
| 56 | + Delay(200); |
| 57 | + |
| 58 | + Application.DoEvents(); |
| 59 | + if (!myCamera.IsAsyncImageRecordingRunning && (myCamera.TotalAsyncImagesRecordedCount > 0)) |
| 60 | + { |
| 61 | + // Prompt the user if he wants to continue or not with the image save |
| 62 | + // if (MessageBox.Show(this, "Image save might take long time!\nAre you sure you want to continue?", "Image Save", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK) |
| 63 | + // { |
| 64 | + // Disable the Image Recording buttons as long as we are saving the images |
| 65 | + //asynchImageRecordingGroupBox.Enabled = false; |
| 66 | +
|
| 67 | + // Get the recorded images as a list |
| 68 | + List<Jai_FactoryWrapper.ImageInfo> imageList = myCamera.GetAsyncRecordedImages(); |
| 69 | + |
| 70 | + // Any images recorded? |
| 71 | +
|
| 72 | + if (imageList != null && (imageList.Count > 0)) |
| 73 | + { |
| 74 | + // Run through the list of recorded images |
| 75 | + int index = myCamera.TotalAsyncImagesRecordedCount - 1; |
| 76 | + Jai_FactoryWrapper.EFactoryError error = Jai_FactoryWrapper.EFactoryError.Success; |
| 77 | + |
| 78 | + // Get the recorded image at this index |
| 79 | + Jai_FactoryWrapper.ImageInfo ii = imageList[index]; |
| 80 | + |
| 81 | + // Are we saving the images in "raw" format or in Tiff? |
| 82 | +
|
| 83 | + // Create local image that will contain the converted image |
| 84 | + Jai_FactoryWrapper.ImageInfo localImageInfo = new Jai_FactoryWrapper.ImageInfo(); |
| 85 | + |
| 86 | + // Allocate buffer that will contain the converted image |
| 87 | + // In this sample we re-allocate the buffer over-and-over because we assume that the recorded images could be |
| 88 | + // of different size (If we have been using the Sequence functionality in the cameras) |
| 89 | + error = Jai_FactoryWrapper.J_Image_Malloc(ref ii, ref localImageInfo); |
| 90 | + |
| 91 | + // Convert the raw image to image format |
| 92 | + error = Jai_FactoryWrapper.J_Image_FromRawToImage(ref ii, ref localImageInfo, 4096, 4096, 4096); |
| 93 | + |
| 94 | + // Save the image to disks |
| 95 | + error = Jai_FactoryWrapper.J_Image_SaveFile(ref localImageInfo, "..\\" + "phone.png"); |
| 96 | + |
| 97 | + //error = Jai_FactoryWrapper.J_Image_SaveFile(ref localImageInfo, "C:\\Users\\aida\\Desktop\\wechat_jump\\" + "phone.png"); |
| 98 | +
|
| 99 | + //Free the conversion buffer |
| 100 | + error = Jai_FactoryWrapper.J_Image_Free(ref localImageInfo); |
| 101 | + |
| 102 | + Application.DoEvents(); |
| 103 | + |
| 104 | + } |
| 105 | + myCamera.StopAsyncImageRecording(); |
| 106 | + myCamera.StopImageAcquisition(); |
| 107 | + myCamera.StartImageAcquisition(true, 5); |
| 108 | + |
| 109 | + // Re-enable the Image Recording buttons |
| 110 | + //asynchImageRecordingGroupBox.Enabled = true; |
| 111 | + //} |
| 112 | + } |
| 113 | + } |
| 114 | + } |
115 | 115 | ```
|
0 commit comments