LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

NIVISION OpenCV Utilities color image

Hello,

I am using NIVISION OpenCV Utilities. Encountered two issues.
The first question
Input the color image into the DLL, DLL uses the opencv split function to obtain the RGB channel datas. When I use the split function, error 1097 occurs and the program freezes in IMAQ Dispose.

 

EXTERN_C void NI_EXPORT OpenCV_MatTo2DArraySplit(NIImageHandle sourceHandle, NIArrayHandle arrayHandle, NIErrorHandle errorHandle) {

    NIERROR error = NI_ERR_SUCCESS;
    ReturnOnPreviousError(errorHandle);
    try {
        if (!sourceHandle || !errorHandle) {
            ThrowNIError(NI_ERR_NULL_POINTER);
        }
        NIImage source(sourceHandle);
        Mat sourceMat;
        ThrowNIError(source.ImageToMat(sourceMat));
        Mat image(20, 20, CV_8UC3, Scalar(100, 128, 200));//b g r
        Mat B;
        image.copyTo(B);
        vector<Mat> channels;
        //Mat aChannels[3];
        split(B, channels);//
        //Mat Temp;
        //Temp = channels[2];
        //NIArray2D<uchar> arrayLV(arrayHandle);
        //arrayLV.SetArray(Temp);//

    }
    catch (NIERROR _err) {
        error = _err;
    }
    catch (...) {
        error = NI_ERR_OCV_USER;
    }

    ProcessNIError(error, errorHandle);
}

henry_2020_0-1701941528050.png

 


The second question
Use Image to Array.vi to obtain array in labview, input the array into DLL, convert array to mat, and finally output it using MatToImage. Error -1074396080, Invalid image type. The mat type is 7, it's not the correct type.

EXTERN_C void NI_EXPORT OpenCV_ArrayToImageRGB(NIImageHandle sourceHandle, NIArrayHandle arrayHandle, NIErrorHandle errorHandle) {

    NIERROR error = NI_ERR_SUCCESS;
    ReturnOnPreviousError(errorHandle);
    try {
        if (!errorHandle) {
            ThrowNIError(NI_ERR_NULL_POINTER);
        }
        NIImage source(sourceHandle);
        Mat sourceMat;      
        NIArray2D<unsigned int> arrayLV(arrayHandle);
        arrayLV.ToMat(sourceMat);
        int a;
        a = sourceMat.type();//Type is 7
        ThrowNIError(source.MatToImage(sourceMat));

    }
    catch (NIERROR _err) {
        error = _err;
    }
    catch (...) {
        error = NI_ERR_OCV_USER;
    }

    ProcessNIError(error, errorHandle);
}

henry_2020_1-1701941557560.png

 

 

0 Kudos
Message 1 of 1
(612 Views)