//camera 的設定
private void Camera_Setup()
{
const Mode k_fmt7Mode = Mode.Mode1;//mode1 644x482
// const Mode k_fmt7Mode = Mode.Mode5;//mode5 is 320x240
const PixelFormat k_fmt7PixelFormat = PixelFormat.PixelFormatMono8;
//const int k_numImages = 3;
busMgr = new ManagedBusManager();
numOfCameras = busMgr.GetNumOfCameras();
if (numOfCameras == 0)
{
// richTextBox1.AppendText("沒有連接camera\n");
busMgr.Dispose();
return;
}
// Console.WriteLine("Number of cameras detected: {0}", numCameras);
ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0);
richTextBox1.AppendText(guid.ToString());
m_camera = new ManagedCamera();
m_camera.Connect(guid);
// Get the camera information
CameraInfo camInfo = m_camera.GetCameraInfo();
// Query for available Format 7 modes
bool supported = false;
Format7Info fmt7Info = m_camera.GetFormat7Info(k_fmt7Mode, ref supported);
if ((k_fmt7PixelFormat & (PixelFormat)fmt7Info.pixelFormatBitField) == 0)
{
// Pixel format not supported!
richTextBox1.AppendText("Pixel format is not supported");
return;
}
Format7ImageSettings fmt7ImageSettings = new Format7ImageSettings();
//fmt7ImageSettings.mode = k_fmt7Mode;
fmt7ImageSettings.mode = Mode.Mode1;
fmt7ImageSettings.offsetX = 0;
fmt7ImageSettings.offsetY = 0;
fmt7ImageSettings.width = fmt7Info.maxWidth;
fmt7ImageSettings.height = fmt7Info.maxHeight;
fmt7ImageSettings.pixelFormat = k_fmt7PixelFormat;
// Validate the settings to make sure that they are valid
bool settingsValid = false;
Format7PacketInfo fmt7PacketInfo = m_camera.ValidateFormat7Settings(
fmt7ImageSettings,
ref settingsValid);
if (settingsValid != true)
{
// Settings are not valid
return;
}
// Set the settings to the camera
m_camera.SetFormat7Configuration(
fmt7ImageSettings,
fmt7PacketInfo.recommendedBytesPerPacket);
// Get embedded image info from camera
EmbeddedImageInfo embeddedInfo = m_camera.GetEmbeddedImageInfo();
embeddedInfo.timestamp.onOff = true;
// Set embedded image info to camera
m_camera.SetEmbeddedImageInfo(embeddedInfo);
}
//主程式(c#)
private void main()
{
busMgr = new ManagedBusManager();
numOfCameras = busMgr.GetNumOfCameras();
if (numOfCameras == 0)
{
richTextBox1.AppendText("連接不到camera!!!\n");
return;
}
richTextBox1.AppendText("camera:" + numOfCameras + "台\n");
cameras = new ManagedCamera[numOfCameras];
processedImage = new ManagedImage[numOfCameras];
rawImage = new ManagedImage[numOfCameras];
for (uint i = 0; i < numOfCameras; i++)
{
ManagedPGRGuid guid = busMgr.GetCameraFromIndex(i);
richTextBox1.AppendText(guid.ToString()+"\n");
cameras[i] = new ManagedCamera();
processedImage[i] = new ManagedImage();
rawImage[i] = new ManagedImage();
cameras[i].Connect(guid);
Cameras_Setup(cameras[i]);
// richTextBox1.AppendText(cameras[i].ToString()+ "\n");
TriggerMode triggerMode = cameras[i].GetTriggerMode();
// Turn off trigger mode
triggerMode.onOff = false;
cameras[i].SetTriggerMode(triggerMode);
cameras[i].StartCapture();
}
}
結果如下圖:
we can open the two cameras in continuous mode.
留言列表