07-23-2014 09:20 AM
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.
07-24-2014 12:23 AM
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
07-24-2014 01:06 AM
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
07-24-2014 04:40 AM - edited 07-24-2014 04:42 AM
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:
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
07-24-2014 07:22 AM - edited 07-24-2014 07:32 AM
I did it!
Thank you so much, klemen. It takes you a lot of time.
Thank you for your attention!