using opencv instead of imagemagick in zbar qr code decoder - opencv

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

Related

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

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)

How to create (DICOM) .dcm file in iOS Objective - C?

DICOM - Digital Imaging and Communications in Medicine, is a standard for handling, storing, printing, and transmitting information in medical imaging. It includes a file format definition and a network communications protocol.
I want to write .dcm file in my ios Project.
Please suggest me any link.
Update: Imebra 4.2 includes the full set of ObjectiveC wrappers, which also work with Swift.
Original alswer:
Imebra allows to read and generate DICOM files also on iOS.
It compiles also for iOS and OS-X, it's written in C++ but it can be used with ObjectiveC method if the extension of the file is .mm instead of .m
Since version 4.0.8.1, Imebra contains also few objectiveC helpers that translate C++ strings to NSStrings (and vice-versa) and extract an UIImage (or NSImage) from an Imebra image
How to generate a DICOM file in Imebra (detailed instructions):
Create an empty dataset:
// We specify the transfer syntax and the charset
std::string transferSyntax(imebra::NSStringToString(#"1.2.840.10008.1.2.1"));
std::string encoding(imebra::NSStringToString(#"ISO 2022 IR 6"));
imebra::DataSet dataSet(transferSyntax, encoding);
Create an image, put it into the dataset:
// Create a 300 by 200 pixel image, 15 bits per color channel, RGB
std::string colorSpace(imebra::NSStringToString(#"RGB"));
imebra::Image image(300, 200, imebra::bitDepth_t::depthU16, colorSpace, 15);
{
std::unique_ptr<WritingDataHandlerNumeric> dataHandler(image.getWritingDataHandler());
// Set all the pixels to red
for(std::uint32_t scanY(0); scanY != 200; ++scanY)
{
for(std::uint32_t scanX(0); scanX != 300; ++scanX)
{
dataHandler->setUnsignedLong((scanY * 300 + scanX) * 3, 65535);
dataHandler->setUnsignedLong((scanY * 300 + scanX) * 3 + 1, 0);
dataHandler->setUnsignedLong((scanY * 300 + scanX) * 3 + 2, 0);
}
}
// dataHandler will go out of scope and will commit the data into the image
}
dataSet.setImage(0, image);
Save the dataset
std::string fileName(NSStringToString(#"path/to/file.dcm"));
imebra::CodecFactory::save(dataSet, fileName, imebra::codecType_t::dicom);
(disclusure: I'm the author of Imebra)

using imread of OpenCV failed when the image is Ok

I encountered a problem when I want to read an image using the OpenCV function imread().
The image is Ok and I can show it in the image display software.
But when I use the imdecode() to get the image data, the data returns NULL.
I will upload the image and the code and hope some one could help me
Mat img = imread(image_name);
if(!img.data) return -1;
The image's link is here: http://img3.douban.com/view/photo/raw/public/p2198361185.jpg
PS: The image_name is all right.
I guess OpenCV cannot decode this image. So is there any way to decode this image using OpenCV?, like add new decode library. By the way, I can read this image using other image library such as freeImage.
Your image is in .gif and it is not supported by OpenCV as of now.
Note OpenCV offers support for the image formats Windows bitmap (bmp),
portable image formats (pbm, pgm, ppm) and Sun raster (sr, ras). With
help of plugins (you need to specify to use them if you build yourself
the library, nevertheless in the packages we ship present by default)
you may also load image formats like JPEG (jpeg, jpg, jpe), JPEG 2000
(jp2 - codenamed in the CMake as Jasper), TIFF files (tiff, tif) and
portable network graphics (png). Furthermore, OpenEXR is also a
possibility.
Source - Click here
You can use something like this, to perform the conversion.
I was able to load your image using imread using this. Also, you can check out FreeImage.
You can also try to use the library gif2numpy. It converts a gif image to a numpy image which then can be loaded by OpenCV:
import cv2, gif2numpy
np_images, extensions, image_specs = gif2numpy.convert("yourgifimage.gif")
cv2.imshow("np_image", np_images[0])
cv2.waitKey()
The library can be found here: https://github.com/bunkahle/gif2numpy It is not dependent on PIL or pillow for this like imageio.
There are two methods to read an image in OpenCV, one is using Mat the other one using IplImage. I see you have used the former one. You can try with the second argument of imread also:
image = imread("image.jpg", CV_LOAD_IMAGE_COLOR); // Read the file
else use IplImage
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <opencv2/core/core.hpp>
IplImage* src = 0;
if( (src = cvLoadImage("filename.jpg",1)) == 0 )
{
printf("Cannot load file image %s\n", filename);
}
If they don't work please check if you have installed libjpeg, libtiff and other dependencies for reading an image in OpenCV.
Hope it would help.

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

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.

Resources