0

我在 C++ 中编写了一个代码来使用 Ueye 相机拍摄快照,但是保存的图片只是白色的,也就是说有时可以看到一小部分道路但仍然只是白色。我相信这是自动参数的问题,但我觉得好像我已经尝试了一切。

下面是我的代码:

void MainWindow::CaptureImage(){
int initcamera = is_InitCamera(&hCam, hWndDisplay);


        if(initcamera != IS_SUCCESS)
        {
            cout<<endl<<"Failed to initialize the camera"<<endl;
            exit(-1);
        }else{

            cout<<endl<<"Initialized Camera"<<endl;
        }

        int camerainfo = is_GetCameraInfo (hCam, &camera_info);
        if(camerainfo != IS_SUCCESS)
        {
            cout<<endl<<"Unable to acquire camera information"<<endl;
            exit(-1);
        }else{

            cout<<endl<<"Camera information required"<<endl;
        }


        int sensorinfo = is_GetSensorInfo (hCam, &sInfo);
        if(sensorinfo != IS_SUCCESS)
        {
            cout<<endl<<"Unable to acquire sensor information"<<endl;
            exit(-1);
        }else{
            cout<<endl<<"Sensor information acquired"<<endl;
        }



        int colormode = is_SetColorMode(hCam, IS_CM_BGR8_PACKED);
        if(colormode != IS_SUCCESS)
        {
            cout<<endl<<"Unable to set the color mode"<<endl;
            exit(-1);
        }else{
            cout<<endl<<"Color mode set"<<endl;
        }

        int pXPos = (sInfo.nMaxWidth);
        int pYPos = (sInfo.nMaxHeight);

        int rit = is_AllocImageMem (hCam,pXPos,pYPos, 24, &m_pcImageMemory, &m_lMemoryId);
        if(rit != IS_SUCCESS)
        {
            cout<<endl<<"UNABLE TO INITIALIZE MEMORY"<<endl;
            system("PAUSE");
            exit(-1);
        }else{
          cout<<endl<<"INITIALIZED MEMORY"<<endl;
        }

        int rat = is_SetImageMem (hCam, m_pcImageMemory, m_lMemoryId);
        if(rat != IS_SUCCESS)
        {
            cout<<endl<<"UNABLE TO ACTIVATE MEMORY"<<endl;
            system("PAUSE");
            exit(-1);
        }else{

        cout<<endl<<"ACTIVATE MEMORY"<<endl;

        }

        double strenght_factor = 1.0;
        int colorcorrection = is_SetColorCorrection(hCam, IS_CCOR_ENABLE, &strenght_factor);

        double pval = 1;
        int whiteb = is_SetAutoParameter(hCam, IS_SET_ENABLE_AUTO_WHITEBALANCE, &pval, 0);

        double gval = 1;
        int gains = is_SetAutoParameter(hCam, IS_SET_ENABLE_AUTO_GAIN, &gval, 0);


        int dummy;
        char *pMem, *pLast;

        IMAGE_FILE_PARAMS ImageFileParams;
        ImageFileParams.pwchFileName = L"./TestImage.bmp";   /// <-- Insert name and location of the image
        ImageFileParams.pnImageID = NULL;
        ImageFileParams.ppcImageMem = NULL;
        ImageFileParams.nQuality = 0;
        ImageFileParams.nFileType = IS_IMG_BMP;


        int sho = is_FreezeVideo(hCam, IS_WAIT);

        if(sho != IS_SUCCESS)
        {
            cout<<endl<<"UNABLE TO ACQUIRE FROM THE CAMERA"<<endl;
            system("PAUSE");
            exit(-1);
        }
        if (sho == IS_SUCCESS){
            int m_Ret = is_GetActiveImageMem(hCam, &pLast, &dummy);
            int n_Ret = is_GetImageMem(hCam, (void**)&pLast);
           }

        if (is_ImageFile(hCam, IS_IMAGE_FILE_CMD_SAVE, (void*)&ImageFileParams, sizeof(ImageFileParams)) == IS_SUCCESS)
        {
            cout << endl << "An Image was saved" << endl;
        }
        else
        {
            cout << endl << "something went wrong" << endl;
        }

        // Releases an image memory that was allocated
        //is_FreeImageMem(hCam, pcImageMemory, nMemoryId);

        // Disables the hCam camera handle and releases the data structures and memory areas taken up by the uEye camera
        is_ExitCamera(hCam);

        }

我已经尝试了很多东西,比如下面的参数,但它仍然只是白色的。我把相机放在房间里,它更暗,图像出来还不错,所以我坚决认为这是由于外面的日光造成的。

const wstring filenameU(filename.begin(), filename.end());
        is_ParameterSet(hCam, IS_PARAMETERSET_CMD_LOAD_FILE,(void*) filenameU.c_str(), 0);

        unsigned int range[3];
                memset(range, 0, sizeof(range));

                is_PixelClock(hCam, IS_PIXELCLOCK_CMD_GET_RANGE, (void*)range, sizeof(range));

        unsigned int maximumPixelClock = range[1];
        is_PixelClock(hCam, IS_PIXELCLOCK_CMD_SET, (void*)&maximumPixelClock, sizeof(maximumPixelClock));

double pval1 = auto_exposure, pval2 = 0;
    double pval1 = 1, pval2 = 0;
is_SetAutoParameter(hCam, IS_SET_ENABLE_AUTO_SENSOR_SHUTTER, &pval1, &pval2);

is_SetAutoParameter(hCam, IS_SET_ENABLE_AUTO_SHUTTER,&pval1, &pval2);

is_SetAutoParameter(hCam, IS_SET_ENABLE_AUTO_SENSOR_FRAMERATE,&pval1, &pval2);

is_SetAutoParameter(hCam, IS_SET_AUTO_WB_OFFSET, &pval1, &pval2);

int desiredFrameRate = 60;
is_SetFrameRate(hCam, desiredFrameRate, &m_actualFrameRate);
4

1 回答 1

0

你不能只拍一张照片,因为曝光可能太高。您必须拍摄几张图像才能让自动曝光控制有机会降低曝光。您必须捕获一些帧的原因是 AEC 是在软件中完成的,并且只有在它获得一些帧时才能开始更改参数。

于 2020-09-16T11:32:03.443 回答