-1

我是 IDS 相机及其 SDK 的新手。现在我正在努力将相机抓取的内存放入 OpenCV Mat 并显示出来。但不知何故,我就是无法得到正确的结果。实际上。显示的框架是黑色和灰色的,我尝试了几种方法来解决这个问题,包括tryout_code这里。以下是我的代码,我感谢任何帮助。非常感谢!

#include <iostream>
#include <stdio.h>
#include <stddef.h>
#include "opencv2/opencv.hpp"
#include "ueye.h"
#include"ueye_tools.h"
using namespace std;
using namespace cv;
#define imgWidth 1280
#define imgHeight 720

void initializeCameraInterface(HIDS* hCam_internal) {

INT nRet = is_InitCamera(hCam_internal, NULL);
if (nRet == IS_SUCCESS) {
    cout << "Camera initialized!" << endl;
}

INT colorMode = IS_CM_BGR8_PACKED;
nRet = is_SetColorMode(*hCam_internal, colorMode);

if (nRet == IS_SUCCESS) {
    cout << "Camera color mode succesfully set!" << endl;
}
INT displayMode = IS_SET_DM_DIB;
nRet = is_SetDisplayMode(*hCam_internal, displayMode);
if (nRet == IS_SUCCESS)
{
    cout << "display set"<< endl;
}
}

Mat getFrame(HIDS* hCam, int width, int height, cv::Mat& mat) {
// Allocate memory for image
char* pMem = NULL;
int memID = 0;
is_AllocImageMem(*hCam, width, height, 24, &pMem, &memID);
is_SetImageMem(*hCam, pMem, memID);
INT nRet=is_FreezeVideo(*hCam, IS_DONT_WAIT);
if (nRet != IS_SUCCESS)
{
    cout << "ERROR: Image could not be captured for IDS camera with ID "
        << hCam << ". Error code: " << nRet << endl;
}
VOID* pMem_b;
int retInt = is_GetImageMem(*hCam, &pMem_b);
if (retInt != IS_SUCCESS) {
    cout << "Image data could not be read from memory!" << endl;
}

memcpy(mat.ptr(), pMem, imgHeight * imgWidth)
is_FreeImageMem(*hCam,pMem, memID);

return mat;
}

int main()
{

HIDS hCam = 0;
initializeCameraInterface(&hCam);

while (true) {
    // Create an image and grab a frame
    Mat current_image(imgHeight, imgWidth, CV_8UC3);
    Mat imtest(imgHeight,imgWidth , CV_8UC3);
    getFrame(&hCam, imgWidth, imgHeight,imtest);

    imshow("test_interface", imtest);

    // Check if we need to stop processing
    if ((int)waitKey(10) >= 0) {
        break;
    }
}

// Release the camera again
is_ExitCamera(hCam);

return 0;
}

结果: 图片

再次感谢!

4

0 回答 0