Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

using OpenCV FileStorage in LabVIEW

Solved!
Go to solution

Excuse me,

I read almost all the vis and cpp files, and I find one image out, it's a kinect'RGB image.

But I still haven't found how to return an Mat to the LabVIEW and display it.

Could you please tell me which project is or how to do it?

Thank you.

0 Kudos
Message 11 of 15
(3,448 Views)

Hello,

 

every example using OpenCV consists of passing the image (actually the image array) pointer to Mat type. Take a look at the Hough circle transformation for example. The basic idea is:

 

Mat inputImage(rows,cols,CV_8U,&imdata[0]);

 

where imdata is the pointer to your image array.

 

Best regards,

K


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 12 of 15
(3,439 Views)

Thank you.

Yes, actually I have already known how to get an image from the LabVIEW and transfer it to the OpenCV Mat before,

But I still don't know how the OpenCV dll return the image to the LabVIEW.

Can the dll return the RGB image, or can only return the CV_8U image and need to combine the three channels in LabVIEW?

Best Regards

0 Kudos
Message 13 of 15
(3,432 Views)
Solution
Accepted by SilvaShi

Hello,

 

something like this should work:

 

*******************************************************************************************************************

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace std;
using namespace cv;

class myclass{
public:    
    Mat img;
    int readimage(){
        img = imread("C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg", CV_LOAD_IMAGE_COLOR);
        if(!img.data)
            return -1;
        return 0;        
    }
};

myclass temp;

extern "C"{
    _declspec (dllexport) int readimage(int *img_rows, int *img_cols);
    _declspec (dllexport) int image_processing(uchar *data);
}

_declspec (dllexport) int readimage(int *img_rows, int *img_cols)
{
    int error_code = temp.readimage();
    if(error_code != 0)
        return -1;
    (*img_rows) = temp.img.rows;
    (*img_cols) = temp.img.cols;
    return 0;
}

_declspec (dllexport) int image_processing(uchar *data)
{
    Mat img_to_LV(temp.img.rows, temp.img.cols, CV_8U, &data[0]);
    cvtColor(temp.img, img_to_LV, CV_BGR2GRAY);
    return 0;    
}

*******************************************************************************************************************

 

and:

 

test_BD.png

 

You can also pass the color image, but take care as OpenCV uses bgr and not rgb notation. In the past I have used 3 seperate channels, building them back in Labview.

 

Best regards,

K

 

 


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
Message 14 of 15
(3,424 Views)

I did it!

Thank you so much, klemen. It takes you a lot of time.

Thank you for your attention!  

 

 

 

0 Kudos
Message 15 of 15
(3,416 Views)