我正在使用带有 16 通道图像采集卡的 Matrox Morphis QxT。当使用内置函数 MdigGrab 和 MdigGrab 连续时,我从我的相机 (Watec 221S2) 获得黑白图像。
我想要来自相机的彩色图像。
我尝试编写自己的代码,但它也提供黑白(单色)图像/视频。我正在使用 OpenCV。
这是我的代码。
#include "opencv\cv.h"
#include "opencv\cxcore.h"
#include "opencv\highgui.h"
#include <mil.h>
char filename[50];
using namespace cv;
int frame=0;
int main(int argc, char **argv)
{
Mat frame1;
MIL_ID MilApplication, /* Application identifier. */
MilSystem, /* System identifier. */
MilGrabImages,
MilDigitizer; /* Image Digitizer */
MIL_INT ImageSizeBand, ColorMode, InputMode, ScanMode;
MIL_DOUBLE FrameRate;
MIL_INT64 ImageWidth, ImageHeight;
/* Allocate default value to application, system and digitizer */
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, M_NULL, &MilDigitizer, M_NULL);
/* Set camera parameters like resolution and frame rate here */
MdigControl(MilDigitizer, M_GRAB_MODE, M_ASYNCHRONOUS);
/* Inquire parameters from frame grabber */
MdigInquire( MilDigitizer, M_SIZE_X, &ImageWidth );
MdigInquire( MilDigitizer, M_SIZE_Y, &ImageHeight );
MdigInquire( MilDigitizer, M_SIZE_BAND, &ImageSizeBand);
MdigInquire( MilDigitizer, M_INPUT_MODE, &InputMode);
MdigInquire( MilDigitizer, M_COLOR_MODE, &ColorMode);
MdigInquire( MilDigitizer, M_SCAN_MODE, &ScanMode);
MdigInquire( MilDigitizer, M_SELECTED_FRAME_RATE, &FrameRate);
printf("\nResolution %d x %d, %d band(s). ", ImageWidth, ImageHeight, ImageSizeBand);
switch(ColorMode)
{
case M_DVI: MosPrintf(MIL_TEXT("DVI "));break;
case M_SDI: MosPrintf(MIL_TEXT("SDI "));break;
case M_COMPOSITE: MosPrintf(MIL_TEXT("Composite "));break;
case M_RGB: MosPrintf(MIL_TEXT("RGB "));break;
case M_EXTERNAL_CHROMINANCE: MosPrintf(MIL_TEXT("Y\\C "));break;
case M_MONOCHROME: MosPrintf(MIL_TEXT("Monochrome "));break;
default: MosPrintf(MIL_TEXT(" "));
}
switch(InputMode)
{
case M_ANALOG: MosPrintf(MIL_TEXT("analog "));break;
case M_DIGITAL: MosPrintf(MIL_TEXT("digital "));break;
default: MosPrintf(MIL_TEXT(" "));
}
switch(ScanMode)
{
case M_PROGRESSIVE: MosPrintf(MIL_TEXT("progressive "));break;
case M_INTERLACE: MosPrintf(MIL_TEXT("interlaced "));break;
default: MosPrintf(MIL_TEXT(" "));
}
MosPrintf(MIL_TEXT("@ %0.2f fps.\n\n"), FrameRate);
/* Allocate grab images. */
MbufAllocColor(MilSystem,
ImageSizeBand,
ImageWidth,
ImageHeight,
8+M_UNSIGNED,
M_IMAGE+M_GRAB+M_PROC,
&MilGrabImages);
frame1.create(ImageHeight, ImageWidth, CV_8UC3);
while(1)
{
MdigGrab(MilDigitizer, MilGrabImages);
MbufGetColor2d( MilGrabImages, M_PACKED+M_BGR24, M_ALL_BANDS, 0,0, 768, 576, (void*)(frame1.data) );
imshow("Channel 0", frame1);
cvWaitKey(50);
}
return 0;
}