デバイスプロパティのハードコーディング
概要
カメラの各種設定を、プロパティ画面のタブ構成に沿って整理しています。これにより、プロパティ画面での操作をハードコーディングによって再現できるようになります。
サンプルプログラム
Software | Software IC Imaging Control 3.5, Visual Studio™ 2022 |
---|---|
サンプル(C#) | CameraDeviceFormatFpsProperty_cs_3.5.zip |
デバイスの設定、ROI・ビニング
// デバイスを指定
icImagingControl1.Device = "DFK 33UR0234";
// ROIやビニングを含むビデオフォーマットの設定
icImagingControl1.VideoFormat = "RGB32 (960x600) [binning 2x]"
// フレームレートの設定
icImagingControl1.DeviceFrameRate = 30.0f;
初めに「どのカメラを使うか(デバイス指定)」「どのような映像を取得するか(解像度・カラーフォーマットの設定)」「どのくらいの速度で撮影するか(フレームレート)」という3つの基本設定を行います。プログラム上でこれらをハードコーディング(コードに直接記述)することで、毎回決まった条件でカメラを初期化・起動できるようになります。
まず最初にicImagingControl1.Deviceで使用するカメラの型番を指定します。
次にVideoFormatプロパティを使って、解像度(ROI)やカラーフォーマット(RGB32など)、スキッピング(画素を間引く手法)やビニング(画素を間引いて感度を上げる手法)を指定します。
最後にDeviceFrameRateにより、1秒間に何枚の画像を取得するか(フレームレート)を設定します。
このように、Device・VideoFormat・FrameRateの3点をコードで固定しておくことで常に同じ条件でカメラから映像を出力することができます。詳細については、以下のページをご参照ください。
VideoFormat・ビニング/スキッピング・ROIの設定
IC Imaging Control3.5(C#/VB.NET) サンプルプログラム
サンプルツールの外観
下記では、各プロパティ画面の設定内容をどのようにハードコーディングで再現するかを、タブごとの項目に分けて記載しています。
[StartUp]タブ
プロパティの設定値をカメラに保存あるいはカメラのプロパティを初期状態にする。
//StartUp Behavior Save Current State
icImagingControl1.VCDPropertyItems.Find<VCDButtonProperty>(new Guid("{8E972004-3B94-4AA4-A899-65F6A1432713}"), new Guid("{8ABB2078-34BA-4B7C-B033-D035E12D9DA6}")).Push();
//Restore Factory Default
icImagingControl1.VCDPropertyItems.Find<VCDButtonProperty>(new Guid("{8E972004-3B94-4AA4-A899-65F6A1432713}"), new Guid("{D6800B86-E461-45B7-88F8-2115113FE728}")).Push();
//Status
int status=icImagingControl1.VCDPropertyItems.Find<VCDButtonProperty>(new Guid("{8E972004-3B94-4AA4-A899-65F6A1432713}"), new Guid("{CFA63B66-55AF-4ABC-B14C-6F460AB3C4F7}")).Value;
[Color]タブ
明るさ、コントラスト、ゲイン、露出の自動/手動切り替えおよび値の調整を行う。
//Hue
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_Hue, VCDGUIDs.VCDElement_Value).Value = 0;
// Saturation
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(VCDGUIDs.VCDID_Saturation, VCDGUIDs.VCDElement_Value).Value =100.0f;
//white balance OnePush
icImagingControl1.VCDPropertyItems.Find<VCDButtonProperty>(VCDGUIDs.VCDID_WhiteBalance, VCDGUIDs.VCDElement_OnePush).Push();
//white balance Auto
icImagingControl1.VCDPropertyItems.Find<VCDSwitchProperty>(VCDGUIDs.VCDID_WhiteBalance, VCDGUIDs.VCDElement_Auto).Switch = false;
//white balance Mode 0:Gray World, 1:temperature
icImagingControl1.VCDPropertyItems.Find<VCDMapStringsProperty>(VCDGUIDs.VCDID_WhiteBalance, VCDGUIDs.VCDElement_WhiteBalanceMode).Value = 0;
//white balance Preset Mode 0:Any, 1:Auto Warm White,2:Auto Cool White,3:Auto Daylight,4:Auto Deep Shade
icImagingControl1.VCDPropertyItems.Find<VCDMapStringsProperty>(VCDGUIDs.VCDID_WhiteBalance, VCDGUIDs.VCDElement_Auto_Preset).Value = 0;
//white balance temperature Preset Mode 0:Sodium - Vapor Lamp,1:Warm Light, 2:Halogen Light, 3:Neutral White, 4:Cool white Fluorescent Light, 5:Cool White/ Daylight(CFL), 6:Daylight, 7:Cool White LED, 8:Blue Sky
icImagingControl1.VCDPropertyItems.Find<VCDMapStringsProperty>(VCDGUIDs.VCDID_WhiteBalance, VCDGUIDs.VCDElement_Auto_TemperaturePreset).Value = 0;
//white balance temperature
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_WhiteBalance, VCDGUIDs.VCDElement_Temperature).Value =7500;
// white balance Red
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(VCDGUIDs.VCDID_WhiteBalance, VCDGUIDs.VCDElement_WhiteBalanceRed).Value = 2.1f;
// white balance Green
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(VCDGUIDs.VCDID_WhiteBalance, VCDGUIDs.VCDElement_WhiteBalanceGreen).Value =2.2f;
// white balance Blue
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(VCDGUIDs.VCDID_WhiteBalance, VCDGUIDs.VCDElement_WhiteBalanceBlue).Value = 1.3f;
[Exposure]タブ
シャープネス、ガンマ、ノイズ除去、反転処理(水平・垂直)の有効/無効を制御。
//Brightness
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_Brightness, VCDGUIDs.VCDElement_Value).Value = 42;
//Contrast
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_Contrast, VCDGUIDs.VCDElement_Value).Value = 0;
// gain Auto
icImagingControl1.VCDPropertyItems.Find<VCDSwitchProperty>(VCDGUIDs.VCDID_Gain, VCDGUIDs.VCDElement_Auto).Switch = false;
// gain
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(VCDGUIDs.VCDID_Gain, VCDGUIDs.VCDElement_Value).Value = 13.0f;
// gain Auto Max Value
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(VCDGUIDs.VCDID_Gain, VCDGUIDs.VCDElement_AutoMaxValue).Value = 33.0f;
// exposure Auto
icImagingControl1.VCDPropertyItems.Find<VCDSwitchProperty>(VCDGUIDs.VCDID_Exposure, VCDGUIDs.VCDElement_Auto).Switch = false;
// exposure
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(VCDGUIDs.VCDID_Exposure, VCDGUIDs.VCDElement_Value).Value = 0.033333;
// exposure AutoReference
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_Exposure, VCDGUIDs.VCDElement_AutoReference).Value = 128;
// exposure AutoMaxValue
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(VCDGUIDs.VCDID_Exposure, VCDGUIDs.VCDElement_AutoMaxValue).Value = 0.250000f;
//highlight Reduction
icImagingControl1.VCDPropertyItems.Find<VCDSwitchProperty>(new Guid("{546541AD-C815-4D82-AFA9-9D59AF9F399E}"), VCDGUIDs.VCDElement_Value).Switch = false;
[Image]タブ
ホワイトバランス、彩度、色温度など色調整に関連するプロパティを設定。
// Sharpness
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_Sharpness, VCDGUIDs.VCDElement_Value).Value =0;
//gamma
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_Gamma, VCDGUIDs.VCDElement_Value).Value = 100;
// denoise
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_Denoise, VCDGUIDs.VCDElement_Value).Value = 0;
// flip horizontal
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_FlipHorizontal, VCDGUIDs.VCDElement_Value).Switch = false;
// flip vertical
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_FlipVertical, VCDGUIDs.VCDElement_Value).Switch = false;
[Special]タブ
トリガー設定、GPIOの読み書き、ストロボ制御などの設定。
// TriggerMode
icImagingControl1.VCDPropertyItems.Find<VCDSwitchProperty>(VCDGUIDs.VCDID_TriggerMode, VCDGUIDs.VCDElement_Value).Switch = false;
// TriggerMode SoftwareTrigger
icImagingControl1.VCDPropertyItems.Find<VCDButtonProperty>(VCDGUIDs.VCDID_TriggerMode, VCDGUIDs.VCDElement_SoftwareTrigger).Push();
// TriggerMode TriggerPolarity
icImagingControl1.VCDPropertyItems.Find<VCDSwitchProperty>(VCDGUIDs.VCDID_TriggerMode, VCDGUIDs.VCDElement_TriggerPolarity).Switch = false;
// Trigger delay
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(VCDGUIDs.VCDID_TriggerMode, VCDGUIDs.VCDElement_TriggerDelay).Value = 0.000000f;
// Trigger debounce time
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(VCDGUIDs.VCDID_TriggerMode, VCDGUIDs.VCDElement_TriggerDebounceTime).Value = 0.000000f;
// Trigger mask time
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(VCDGUIDs.VCDID_TriggerMode, VCDGUIDs.VCDElement_TriggerMaskTime).Value = 0.000000f;
// Trigger noise suppression time
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(VCDGUIDs.VCDID_TriggerMode, VCDGUIDs.VCDElement_TriggerNoiseSuppressionTime).Value = 0.000000f;
// Trigger burst count
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_TriggerMode, new Guid("{B4109964-77E4-4AF3-ACA8-45BBAA861B5C}")).Value = 2;
// Trigger burst interval
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_TriggerMode, new Guid("{A9715AB3-69AE-454D-8DF5-7E06D87C109C}")).Value = 200;
// Trigger override mode 0:Off, 1:Readout 読み取り専用
int triggerReadout=icImagingControl1.VCDPropertyItems.Find<VCDMapStringsProperty>(VCDGUIDs.VCDID_TriggerMode, new Guid("{7685BF04-C9C9-4AE2-BA69-1278B77F97F6}")).Value ;
// GPIO Input Mode 読み取り専用
int gpininputMode=icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_GPIO, VCDGUIDs.VCDElement_GPIOIn).Value ;
// GPIO Read
icImagingControl1.VCDPropertyItems.Find<VCDButtonProperty>(VCDGUIDs.VCDID_GPIO, VCDGUIDs.VCDElement_GPIORead).Push();
// GPIO Output Mode 読み取り専用
int gpinoutputMode = icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_GPIO, VCDGUIDs.VCDElement_GPIOOut).Value = 0;
// GPIO Write
icImagingControl1.VCDPropertyItems.Find<VCDButtonProperty>(VCDGUIDs.VCDID_GPIO, VCDGUIDs.VCDElement_GPIOWrite).Push();
//strobe
icImagingControl1.VCDPropertyItems.Find<VCDSwitchProperty>(VCDGUIDs.VCDID_Strobe, VCDGUIDs.VCDElement_Value).Switch = false;
//strobe mode
icImagingControl1.VCDPropertyItems.Find<VCDMapStringsProperty>(VCDGUIDs.VCDID_Strobe, VCDGUIDs.VCDElement_StrobeMode).Value = 0;
//strobe polarity
icImagingControl1.VCDPropertyItems.Find<VCDSwitchProperty>(VCDGUIDs.VCDID_Strobe, VCDGUIDs.VCDElement_StrobePolarity).Switch = false;
[Color Correction]タブ
カラーマトリックス補正の各成分(RR, RG, ... BB)を細かく設定可能。
//color correction matrix
icImagingControl1.VCDPropertyItems.Find<VCDSwitchProperty>(new Guid("{7F7E24E3-7162-42EF-BF5D-99A359CB32F2}"), VCDGUIDs.VCDElement_Value).Switch = true;
//RR
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{7F7E24E3-7162-42EF-BF5D-99A359CB32F2}"), new Guid("{57480AA0-2883-4C7D-A066-357D07C4527D}")).Value = 1.71f;
//RG
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{7F7E24E3-7162-42EF-BF5D-99A359CB32F2}"), new Guid("{57480AA1-2883-4C7D-A066-357D07C4527D}")).Value = 1.72f;
//RB
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{7F7E24E3-7162-42EF-BF5D-99A359CB32F2}"), new Guid("{57480AA2-2883-4C7D-A066-357D07C4527D}")).Value = 1.73f;
// GR
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{7F7E24E3-7162-42EF-BF5D-99A359CB32F2}"), new Guid("{57480AA3-2883-4C7D-A066-357D07C4527D}")).Value = 1.74f;
//GG
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{7F7E24E3-7162-42EF-BF5D-99A359CB32F2}"), new Guid("{57480AA4-2883-4C7D-A066-357D07C4527D}")).Value = 1.75f;
// GB
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{7F7E24E3-7162-42EF-BF5D-99A359CB32F2}"), new Guid("{57480AA5-2883-4C7D-A066-357D07C4527D}")).Value = 1.76f;
// BR
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{7F7E24E3-7162-42EF-BF5D-99A359CB32F2}"), new Guid("{57480AA6-2883-4C7D-A066-357D07C4527D}")).Value = 1.77f;
// BG
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{7F7E24E3-7162-42EF-BF5D-99A359CB32F2}"), new Guid("{57480AA7-2883-4C7D-A066-357D07C4527D}")).Value = 1.78f;
// BB
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{7F7E24E3-7162-42EF-BF5D-99A359CB32F2}"), new Guid("{57480AA8-2883-4C7D-A066-357D07C4527D}")).Value = 1.79f;
[Auto ROI]タブ
トーンマッピングの有効化、強度、グローバル輝度調整などを設定。
//auto functions ROI
icImagingControl1.VCDPropertyItems.Find<VCDSwitchProperty>(new Guid("{124922E5-81C7-4587-867D-7BA16AF79079}"), VCDGUIDs.VCDElement_Value).Switch = false;
// auto functions ROI preset mode 0:Full Sensor, 1:Custom Rectangle, 2:Center 50 %, 3:Center 25 %, 4:Bottom Half, 5:Top Half
icImagingControl1.VCDPropertyItems.Find<VCDMapStringsProperty>(new Guid("{124922E5-81C7-4587-867D-7BA16AF79079}"),new Guid("{93D840ED-B7B8-45FE-91E2-18E68C41AFC3}")).Value = 0;
// auto functions ROI left
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{124922E5-81C7-4587-867D-7BA16AF79079}"), VCDGUIDs.VCDElement_AutoRoiLeftRelative).Value = 50.0f;
// auto functions ROI top
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{124922E5-81C7-4587-867D-7BA16AF79079}"), VCDGUIDs.VCDElement_AutoRoiTopRelative).Value = 50.0f;
// auto functions ROI width
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{124922E5-81C7-4587-867D-7BA16AF79079}"), VCDGUIDs.VCDElement_AutoRoiWidthRelative).Value = 50.0f;
// auto functions ROI height
icImagingControl1.VCDPropertyItems.Find<VCDAbsoluteValueProperty>(new Guid("{124922E5-81C7-4587-867D-7BA16AF79079}"), VCDGUIDs.VCDElement_AutoRoiHeightRelative).Value = 50.0f;
[Partial Scan]タブ
ROIの切り出し位置の開始位置を設定。
// partial scan auto
icImagingControl1.VCDPropertyItems.Find<VCDSwitchProperty>(VCDGUIDs.VCDID_PartialScanOffset, VCDGUIDs.VCDElement_PartialScanAutoCenter).Switch = false;
// partial scan X方向のオフセット
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_PartialScanOffset, VCDGUIDs.VCDElement_PartialScanOffsetX).Value = 0;
// partial scan Y方向のオフセット
icImagingControl1.VCDPropertyItems.Find<VCDRangeProperty>(VCDGUIDs.VCDID_PartialScanOffset, VCDGUIDs.VCDElement_PartialScanOffsetY).Value = 0;