Showing results for 
Search instead for 
Did you mean: 

Cannot convert OpenCV Mat to IMAQ image.ctl format

Hi all,


I'm using LabVIEW 2016 with the NIVision OpenCV Utility installed. I'm trying to learn calling OpenCV library from LabVIEW so I build a very simple VI that grabs image from webcam, do a thresholding (OpenCV library), and output the result image. The OpenCV part works fine as I can save the images from OpenCV code. However I encountered this problem that the image cannot be displayed or saved in LabVIEW panel. 


I've checked the sample "OpenCV motion detection" as it also has an image output. I noted there are basically three lines of codes I need to add in for the conversion, which I have followed exactly in my codes:


EXTERN_C void NI_EXPORT NIVisOpenCV_GetMovingObjectMask(int handle, NIImageHandle sourceHandle, NIImageHandle outMaskHandle, NIErrorHandle errorHandle){

NIImage mask(outMaskHandle);

Mat outMask;




I attach my VI and codes here. Hope can have some suggestions. Thanks!


EXTERN_C void NI_EXPORT NIVisOpenCV_Test(int thre, NIImageHandle sourceHandle, NIImageHandle grayImageHandle, NIArrayHandle rectLV, NIErrorHandle errorHandle)
try {
NIImage source(sourceHandle);
NIImage gray(grayImageHandle);

NIArray1D<LV_Rect> rect(rectLV);

//Do image conversions
Mat sourceMat;

Mat greyImg, procImg;
cvtColor(sourceMat, greyImg, CV_BGR2GRAY);
threshold(greyImg, procImg, thre, 255, THRESH_BINARY_INV);

imwrite("D:\\proc.jpg", procImg);

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



Download All
0 Kudos
Message 1 of 1