10-05-2016 03:11 AM
I know how to pass one image from OpenCV to LabView. I have a FOR loop in OpenCV that generates multiple images. How do I pass those images back to LabView?
See my code below?
MedianFilter.cpp code (DLL source code):
#include <opencv2/imgproc/imgproc.hpp> #include <opencv2\highgui\highgui.hpp> #include<sstream> #include <iostream> using namespace std; using namespace cv; // extern C extern "C" { _declspec (dllexport) void MedianFilter(unsigned char *imageIN, int rows, int cols, int kernel_size, unsigned char *imageOUT, int i); } _declspec (dllexport) void MedianFilter(unsigned char *imageIN, int rows, int cols, int kernel_size, unsigned char *imageOUT, int i) { Mat image_input(rows, cols, CV_8U, &imageIN[0]); // THIS IS THE INPUT IMAGE, POINTER TO DATA //imshow("STAGE 1: Original Image", image_input); Mat dst, draw; char zBuffer[55]; stringstream ss; string name = "MedianFilteredImage"; string type = ".jpg"; Mat image_output(rows, cols, CV_8U, &imageOUT[0]); // THIS IS THE OUTPUT IMAGE, POINTER TO DATA for (i = 1; i<23; i = i + 2) { //copy the text to the "zBuffer" _snprintf_s(zBuffer, 55, "Kernel Size : %d x %d", i, i); //Median smoothing medianBlur(image_input, image_output, i); //put the text in the "zBuffer" to the "dst" image putText(image_output, zBuffer, Point(image_input.cols / 4, image_input.rows / 8), CV_FONT_HERSHEY_COMPLEX, 1, Scalar(255, 255, 255), 2); //Save filtered image(i) ss << name << (i) << type; string filename = ss.str(); ss.str(""); /*imwrite(filename, image_output);*/ //char file_name[100]; //sprintf(file_name, "medianFilteredImages/MedianFilteredImage%d.jpg", i); //imwrite(file_name, image_output); //imwrite("medianFilteredImages/zBuffer.jpg", image_output); //show the blurred image with the text imshow("STAGE 1: Median filtered Image", image_output); bool bSuccess = imwrite("../OpenCV_saved_images/OpenCV_saved_images.jpg", image_output); if (!bSuccess) { string mystr; float price = 0; int quantity = 0; cout << "Enter price: "; getline(cin, mystr); stringstream(mystr) >> price; cout << "Enter quantity: "; getline(cin, mystr); stringstream(mystr) >> quantity; cout << "Total price: " << price*quantity << endl; cout << "ERROR : Failed to save the image" << endl; //putText(); //sprintf("%b , ERROR : Failed to save the image", bSuccess.toString()); //system("pause"); //wait for a key press } //wait for 2 seconds waitKey(1000); } }
10-05-2016 06:32 AM
10-22-2016 08:55 AM - last edited on 04-18-2024 10:01 AM by Content Cleaner
I apologize for the late response. I am only seeing that thread now. NI recently released a set of VIs to easily integrate LabVIEW and Vision Development Module with OpenCV. You can download them at this link:
https://www.ni.com/en/support/downloads/tools-network/download.vision-opencv-utilities.html
They contain examples to easily get started.
Hope this helps.
Christophe