Ask Your Question

Leena's profile - activity

2016-02-13 21:57:44 -0500 received badge  Famous Question (source)
2016-01-07 05:55:25 -0500 received badge  Student (source)
2015-07-20 06:16:49 -0500 received badge  Notable Question (source)
2015-05-20 03:04:27 -0500 received badge  Popular Question (source)
2014-05-20 05:34:42 -0500 commented question Read and write Mat to xml file under root node

Yeah I just tested and It works great, It just that I wanted a different name for the root node and read a mat from a node lower than the root node for examle :

<?xml version="1.0"?> <hello> <world> <opencv_storage> Here my data from the mat <opencv_storage> </world> </hello>

But I think I have a idea about how to do this on a inderect way. Thanks for your answer

2014-05-20 04:38:35 -0500 asked a question Read and write Mat to xml file under root node

Hello,

I am trying to save Mat to a xml file. I follow this tutorial and its works very well : link

The problem I have a xml with some value before and if I tried to write in this file, It will erase all my data to remplace with a root node <opencv_storage>. For example if tried to write in a xml like this :

<?xml version="1.0"?>
<hello>
<world>hello world</world>
</hello>

If I tried to write in this file the program will with a error :

OpenCV Error: Parsing error (test.xml(2): <opencv_storage> tag is missing) in icvXMLParse, file ..\..\..\..\opencv\modules\core\src\persistence.cpp, line 2281

I can resolve this problem creating an empty node <\opencv_storage> in the xml file, like this :

<?xml version="1.0"?>
<hello>
<world>hello world</world>
<opencv_storage></opencv_storage>

And then close the root node (don't why if I put the </hello> in the xml file it will be after <opencv_storage>).

But I still have problems to read the mat, because I think FileStorage is waiting a root node <opencv_storage>, so I was wondering is somebody have an idea to resolve this problem.

Best regards

2014-05-19 07:28:42 -0500 commented answer Convert Mat to byte[] in C++

Yeah I think you are right, If we pass a image in input we should know it's size too and type too. I will look to a way to pass a direct Bitmap in jni, thanks again for you help :)

2014-05-19 07:10:23 -0500 commented answer Convert Mat to byte[] in C++

The context : I will create a application C++ wich will do some image processing and return a image. This application will be a library .dll or .so in order to be used by other langage like Java trough JNA. The main function of the library is : byte* doSomeImageProcessing(string "pathToConf", byte* data);. My superior doen'st want to see a single object of opencv outside the library, that is why I was thinking of using byte* in return and create a Bitmap from this byte*.

2014-05-19 05:52:33 -0500 commented answer Convert Mat to byte[] in C++

I am sorry but I don't understand your answer. I will receive byte * without knowing what is the image in input (dim image,gray or color image etc...) so I was just wondering is there a way to do this. Anyway thanks again for your answers

2014-05-19 05:09:17 -0500 commented answer Convert Mat to byte[] in C++

Thanks It works greats ^^ But I have two another questions : To reconvert byte * to Mat do I must always know the size and the number of channel of the image ? On a java side, once I manage to convert a byte * to byte[] can I create a Bitmap image without knonwing the size of the image too ?

2014-05-19 05:04:58 -0500 received badge  Scholar (source)
2014-05-19 05:04:04 -0500 received badge  Supporter (source)
2014-05-19 04:26:15 -0500 received badge  Editor (source)
2014-05-19 04:25:50 -0500 asked a question Convert Mat to byte[] in C++

Hello,

For a project I have to return a byte[] in C++ in order to be implement by wrapper like java. I am not very experimented with byte and I don't know what it's the best approach. I tried this code :

typedef unsigned char byte;

byte[] matToBytes(Mat image)
{
   int size = image.rows*image.cols;
   byte bytes[size];
   std::memcpy(bytes,image.data,size * sizeof(byte);
}

And I must be able to reconvert this byte[] in Mat. So I tried this code too :

Mat BytestoMat(byte[] bytes,int width,int height)
{
    Mat image = Mat(height,width,CV_8UC3,bytes);
    return image;
}

Do you think it a good approach or is there a better approach ? I saw there is function like imread and imwrite in opencv but i don't if it can do the same thing.

Best regards

2014-05-02 04:08:17 -0500 commented question JNI with opencv_java248

Ok, thank you for your answer. I succed to compile in .dll opencv_Filter and the program run.

2014-05-02 03:51:54 -0500 commented question JNI with opencv_java248

Thank you for your answer, so I must compile opencv_Filter.dll into a .dll and use this instead of opencv_java248.dll ? I don't know how I can do that on Windows on a easy way and I must include opencv in the compilation, right ?

2014-05-02 03:28:15 -0500 asked a question JNI with opencv_java248

Hello, I would like to write a JNI on Java with opencv_java248 but I'am having some difficulties. I know I could write it in Java thanks to opencv248.jar and opencv_java248.dll but my superior want me to do a JNI. So I read tutorials,docs etc.. and here what I wrote.

Filter.java :

import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;

public class Filter {

static
{
    System.loadLibrary("opencv_java248");
}

private static native void doNativeHistogramEqualisation(long src);

public static Mat doHistogramEqualisation(Mat src)
{
    doNativeHistogramEqualisation(src.getNativeObjAddr());
    return src;
}

public static void main(String[] args) 
{
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);


    for (int i = 1;i<13;i++)
    {
        String path = i+".jpg";
        Mat image = Highgui.imread("images/"+path);
        Mat dst = new Mat();
        dst = doHistogramEqualisation(image);
        //doHoughLineTransform(image, 30, 50, 20, 14);
        Highgui.imwrite("output/"+path,dst);
    }   
}

opencv_Filter.h: (Generated by javah)

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class opencv_Filter */

#ifndef _Included_opencv_Filter
#define _Included_opencv_Filter
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     opencv_Filter
 * Method:    doNativeHistogramEqualisation
 * Signature: (J)J
*/
JNIEXPORT void JNICALL Java_opencv_Filter_doNativeHistogramEqualisation
(JNIEnv *, jclass, jlong);

#ifdef __cplusplus
}
#endif
#endif

opencv_Filter.cpp:

#include "opencv_Filter.h"

#include <iostream>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

JNIEXPORT void JNICALL Java_opencv_Filter_doNativeHistogramEqualisation
(JNIEnv *jenv, jclass,    jlong Jsrc)
{
Mat* src = (Mat*) Jsrc;
src->create(rows, cols, type);
std::memcpy(src->data, data, src->step * src->rows);

if(src.channels() != 1)
    cvtColor( src, src, CV_BGR2GRAY );
equalizeHist( src, src );
return;
}

I make sure the opencv_java248.dll is linked but I keep getting the errors :

Exception in thread "main" java.lang.UnsatisfiedLinkError:        opencv.Filter.doNativeHistogramEqualisation(J)V
    at opencv.Filter.doNativeHistogramEqualisation(Native Method)
    at opencv.Filter.doHistogramEqualisation(Filter.java:18)
    at opencv.Filter.main(Filter.java:32)

I check the type of error and It say come from the native method but I can't figure what is the problem. I think it's because I am not compiling the .cpp but I'm not sure about that.

Thank you, very much if you can help me. Regards