How can i convert a const mat image into an Iplimage? - opencv

i'm working on the extraction of an algorithm from a source existing library. Inside a function there is a declaration of IplImage initialized with a Const cv::mat :
IplImage *frame = new IplImage(img_input);
compiling i get the following error:
no matching function for call to ‘_IplImage::_IplImage(const cv::Mat&)
I think this is because the library uses an old version of opencv. So the question is how can i get the same result in the new version of opencv?(i'm using the latest)

Related

How to use opencv cuda module log function

I'm trying to work with Opencv CUDA module, specially refer to cv::cuda::log function.
First, I'll give to details Opencv compilation.
I compiled Opencv with WITH_CUDA flag on, took the libs and dlls from the compilation, however I copied the headers files from the downloaded opencv folder, since the compilation folder does't include headers by default.
I wonder, whether is this the right thing to do ?
Second, I tried to use the cv::cuda:: function.
I include the cuda.hpp header
#include "opencv2/core/cuda.hpp"
cv::cuda::GpuMat source, dest;
GpuMat compiles great for me, However I don't know which file should I include in order to work with the log function. when I write the following line
cv::cuda::log(source, dest);
I kept on getting the error message:
error: C2039: log in not a member of cv::cuda
Windows 7, Visual studio 2013, Opencv 3.0.0, platform: 64 bit, CUDA toolkit 6.5
Third, I'd like to know about Opencv CUDA implementation, does it utilize npp functionality? Opencv vs npp, which one is better to use ?
I could easly write my code using npp, however I'd like to know the opencv CUDA module.
Thanks
After couple days of searching, I'd like to share my knowledge
First thing I was doing wrong, was taking the headers from Opencv compilation, the right thing to do is taking the header from all the Opencv modules (each module individually).
Second, After Opencv compilation with CUDA flag everything worked great.
Third, Several opencv CUDA functions does utilize NPP
Forth, Use github
This code should work for OpenCV 3.1:
#include <opencv2/opencv.hpp>
#include <opencv2/cudaarithm.hpp>
int main()
{
cv::Mat img = cv::imread("img.jpg", cv::IMREAD_GRAYSCALE);
cv::Mat img_32f;
img.convertTo(img_32f, CV_32F);
//To avoid log(0) that is undefined
img_32f += 1.0f;
cv::cuda::GpuMat gpuImg, gpuImgLog;
gpuImg.upload(img_32f);
cv::cuda::log(gpuImg, gpuImgLog);
cv::Mat imgLog, imgLog_32f;
gpuImgLog.download(imgLog_32f);
double min, max;
cv::minMaxLoc(imgLog_32f, &min, &max);
imgLog_32f.convertTo(imgLog, CV_8U, 255.0/(max-min), -255.0*min/(max-min));
cv::imshow("img", img);
cv::imshow("imgLog", imgLog);
cv::waitKey(0);
return 0;
}

Conversion between opencv and javacv

I'm thinning an binary image. I found code done by using opencv. Here is the code.
eroded = cv2.erode(img,element)
temp = cv2.dilate(eroded,element)
temp = cv2.subtract(img,temp)
skel = cv2.bitwise_or(skel,temp)
img = eroded.copy()
I'm trying to convert this code to java via javacv. Both erosion and dilation completed successfully as follows.
skelImg=cvCloneImage(otsuImg);
cvErode(otsuImg, skelImg, null, 1);
cvDilate(skelImg, skelImg, null, 1);
But I couldn't find javacv code for cv2.subtract(IplImage,IplImage). Can someone help me out with this?
There is one subtract function in Core. See this for better understanding
Rather than use the javacv wrapper to OpenCV's deprecated API, consider using the following methods from OpenCV's official Java API:
org.opencv.imgproc.Imgproc.erode
org.opencv.imgproc.Imgproc.dilate
org.opencv.core.Core.subtract
org.opencv.core.Core.bitwise_or

cvLoadImage works with string constant but not c_str()

I am using cvloadimage to open an image in my program. The images are in a external directory, generated using the current time in the filename.
When I try to load images in this way:
IplImage *image = cvLoadImage(path.c_str,CV_LOAD_IMAGE_COLOR);
the image structure will be NULL and the application will stop with q segmentation fault.
When I try to load an image this way:
IplImage *image = cvLoadImage("path/images/image_2012_11_25.jpg",CV_LOAD_IMAGE_COLOR);
then it works great.
Is the problem that cvLoadImage can't accept any type of text, only const char*?
But c_str() converts string to char*, right?
How can I solve this problem?
I had the same problem with writing into a file so I used the code below:
const char *M=s.c_str();
file.write(M,s.size());
hope it works...

JavaCV Stitching

I am trying to stitch multiple images by using JavaCV 0.1 and OpenCV 2.4.0 in Java, i use this code for stitching images :
stitcher = Stitcher.createDefault(false);
MatVector images = new MatVector(imageN.size());
for(...){
CvArr image = cvLoadImage(imageN);
images.put(index,image);
}
MatVector result = new MatVector(1);
int status = stitcher.stitch(images,result);
if( status == stitcher.OK )
{
cvSaveImage(result.getIplImage(0));
}
NOTE 1 : Loaded images in this example are valid image for stitching.
NOTE 2 : C++ version of the code runs with no problem on current configuration
In stitcher.stitch method opencv throws an assertion exception such as "k == MAT". How should i fix this? Is MatVector usage is right in this sample code?
Thanks...
I found it, it is a bug related with JavaCv.
Actually JavaCv is not guilty.OpenCV stitcher API uses cv::OutputArray for returning stitched image but this method casts cv::OutputArray to cv::Mat when executing. JavaCV ports OpenCV method only by using parameter interface and so it converts the parameter as std::vector, this results as a assertion failure.
It is required to convert std::vector to Mat to make it working. I don't know any other way exist for this conversion but otherwise it is possible to be fixed by only lib's author.
It is said that c++ version is working but in fact, it is working when pano parameter is given as cv::Mat, when std::vector is entered it gives the same failure assertions again.

using opencv instead of imagemagick in zbar qr code decoder

I am writing a qr code decoder using Zbar api. I am using windows pre built libraries . I used the following code to load the image to ZBar
IplImage *src=cvLoadImage("image.png",CV_LOAD_IMAGE_GRAYSCALE);
ImageScanner scanner;
scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
int width = src->width;
int height = src->height;
uchar* raw = (uchar *)(src->imageData);
Image image(width, height, "Y800", raw, width * height);
int n = scanner.scan(image);
But it failed to decode the image. Am I using the correct way to read image data using opencv ? . When I tested only one image decoded and failed for all others . But it is working well when I used the zbarimg command line option

Resources