Matrox成像库中的MdigGrab是给彩色图像还是黑白图像

时间:2019-03-01 04:09:34

标签: opencv image-processing frame-grab

我正在将Matrox Morphis QxT与16通道帧采集器一起使用。连续使用内置功能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;
}

1 个答案:

答案 0 :(得分:0)

经过米尔帮助中心,我得到了答案。

是的,MdigGrab提供彩色图像。 我只需要将DCF从M_CCIR更改为M_PAL(680x480)或M_NTSC(786x576)。