04-29-2015 03:36 AM
Hi, I'm using the vi below to aquire an image from labview then pass it to an opencv dll code through , first getting image pixel pointer and then passing the result parameters to create a "Mat " in my c++ code. Untill this point everything works. Now I do some processing in opencv the final resultiing image I want to bring it back to LabView. This I can't figure it out. (btw the image is a binary image). How can I get this image back??? please help
P.S. actually what I get in image3 is the same image I captured from LV.
Solved! Go to Solution.
04-29-2015 07:27 AM - edited 04-29-2015 07:45 AM
Hello,
first of all, if you've got only a binary image, U8 datatype is sufficient. Also, be careful since Labview uses RGB and OpenCV (by default) BGR notation.
I have never used the "map pixel pointer" in Labview, instead I always copy the image to a 2D array and than pass a pointer to Mat pixel matrix. I have never seen any performance issues with this. Using high resolution counter, it takes ~1.2 ms on average to copy images with the size of 1920x1080 pixels (on my low(mid) range 3 years old laptop). Of course, the "map pixel pointer" should be faster, but I cannot say how much faster.
There are numerous examples here if you are interested:
https://decibel.ni.com/content/blogs/kl3m3n
In your case, try using:
Mat your_image(rows,cols,CV_8U,&imdata[0])
where the function prototype is:
_declspec (dllexport) int your_funciton (uchar *imdata, int cols, int rows)
and then process the image (your_image).
You can attach a simple C++ source code along with the Labview program in order to help you further.
Best regards,
K
P.S. I see now that the pixel pointer is U64 datatype. Is this the only option?
It also seems that you need to unmap the pointer:
http://zone.ni.com/reference/en-XX/help/370281P-01/imaqvision/imaq_getimagepixelptr_example/
04-30-2015 02:15 AM
Hello,
a simple example:
OpenCV code:
#include <opencv2/imgproc/imgproc.hpp> using namespace std; using namespace cv; // extern C extern "C" { _declspec (dllexport) int CannyEdges(unsigned char *imageIN, int rows, int cols, double threshold1, double threshold2, int kernel_size, unsigned char *imageOUT); } _declspec (dllexport) int CannyEdges(unsigned char *imageIN, int rows, int cols, double threshold1, double threshold2, int kernel_size, unsigned char *imageOUT) { // check odd kernel size if(kernel_size % 2 == 0) return -1; // allocate memory Mat image_input(rows, cols, CV_8U, &imageIN[0]); // THIS IS THE INPUT IMAGE, POINTER TO DATA Mat image_output(rows, cols, CV_8U, &imageOUT[0]); // THIS IS THE OUTPUT IMAGE, POINTER TO DATA // blur before canny blur(image_input, image_output, Size(3,3)); // canny Canny(image_output, image_output, threshold1, threshold2, kernel_size); return 0; }
You can operate directly on the "imageIN" by eliminating the image_output and replacing with image_input.
Labview code:
I am attaching the Labview code (2013) and the .dll for you to test.
Hope this helps.
Regards,
K
05-01-2015 12:43 AM
That looks interesting, but in my case I have to bring a RGB image not a grayscaled one.
05-04-2015 11:33 AM
Thanks alot for your help. I managed to merge both techniques (what you suggested+the image pixelpointer) and I got my result. 🙂
05-04-2015 12:06 PM - edited 05-04-2015 12:08 PM
@RYagan wrote:
That looks interesting, but in my case I have to bring a RGB image not a grayscaled one.
Just declare a pointer to uint32, instead of uint8. Modify the code and it should work.
Anyway, great you managed to get it working. Did you consider rgb to bgr conversion? Just curious.
Regards,
K
05-04-2015 01:05 PM
I'm not sure if that will work, what I've tried to do before is to wire my RGB image to the Image to array block but LV showed an error. Also, the array can't be encoded to U32 type. (not showing in the block terminals)
Also, I didn't perform rgb to bgr conversion between LV and OpenCV. Doing this will invert my image colors wrong wise . OpenCV accepeted the image as is.
08-27-2015 01:22 AM
Hello,
a late reply, but if you create a CV_8UC4 image in OpenCV and pass the pointer to the U32 image array it works properly.
The array can be encoded in U32 (RGBA image), but you will find this on the color pallete not grayscale.
Can you share your solution? Just out of curiosity.
Best regards,
K
10-15-2015 04:05 AM
I suspect that opencv expects a grey scale image for canny.
i.e it will fail with any other type.
10-15-2015 04:48 AM
Hello,
yes, it needs 8-bit single channel image:
http://docs.opencv.org/modules/imgproc/doc/feature_detection.html?highlight=canny#canny
Regards,
K