bytedeco / javacpp-presets

The missing Java distribution of native C++ libraries
Other
2.67k stars 742 forks source link

trying to write opencv mat object into xml file using FileStorage class #473

Open tehseenmayar opened 7 years ago

tehseenmayar commented 7 years ago

hello guys i am trying to write an opencv mat object into xml file to preserve it for later use but i got the following error. i don't know is there any problem with my code or something else. any type of help would be appreciated.. Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopencv_core in java.library.path

this is my java code

 opencv_core.FileStorage mfs= new opencv_core.FileStorage(String.valueOf(mymagnitude), opencv_core.FileStorage.WRITE);
                mfs.open("test.xml", opencv_core.FileStorage.WRITE);
                mfs.release();

"mymagnitude" is the mat object which i am trying to write to a file

saudet commented 7 years ago

Which platform?

tehseenmayar commented 7 years ago

windows

tehseenmayar commented 7 years ago

i have fixed that "no jniopencv_core in java.library.path" error but now it writes an empty xml file so i think the problem is in my java code but i can't fix it so kindly give me some sample code to write that mat object. i will appreciate any help.

tehseenmayar commented 7 years ago

i don't know how to implement the "write" method of "FileStorage" class

saudet commented 7 years ago

Could you post your code?

tehseenmayar commented 7 years ago
 Mat mymagnitude=new Mat();
mymagnitude=obj.transformImage(path);
opencv_core.FileStorage mfs= new opencv_core.FileStorage(String.valueOf(mymagnitude), opencv_core.FileStorage.WRITE);
mfs.open("test.xml", opencv_core.FileStorage.WRITE);
mfs.release();

i don't know how to implement the write method of FileStorage class

saudet commented 7 years ago

Just call it, what is the issue?

tehseenmayar commented 7 years ago

okay now i have implemented like this:

  opencv_core.FileStorage mfs= new opencv_core.FileStorage(String.valueOf(mymagnitude), opencv_core.FileStorage.WRITE);
                mfs.open("E:/test.xml", opencv_core.FileStorage.WRITE);

               mfs.write("test", String.valueOf(mymagnitude));

and now the output is this

<?xml version="1.0"?>
<opencv_storage>
<test>"Mat [ 288*192*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x1bad9dc0, dataAddr=0x1cf0dee0 ]"</test>
</opencv_storage>

but i am not sure that this is the whole data of my mat object so i wan to read it from file and store it in the mat and then display that mat as an image to make myself sure that i have got the whole data of my mat.. so can you tell me how can i read it back from xml file and convert it back to mat?

saudet commented 7 years ago

Use the functions as you would from C++, it works.

tehseenmayar commented 7 years ago

what function? i am new to opencv so kindly help me.. what function and what are it's parameter?

saudet commented 7 years ago

http://docs.opencv.org/2.4/modules/core/doc/xml_yaml_persistence.html

tehseenmayar commented 7 years ago

i am using "opencv_core.FileStorage" and i want to write opencv_core.Mat object as image but i cannot find "Imgcodec.imwrite " method in it just like it's in "org.opencv.core" so how can i write opencv_core mat as an image?

tehseenmayar commented 7 years ago

i have fixed the previous problem and now i am trying to read "xml" file and store the data into mat object and then i save that mat as image but the mat is empty.. here is my code

 opencv_core.Mat mymat=new opencv_core.Mat();
 opencv_core.FileStorage mfs= new opencv_core.FileStorage("E:/test.xml", opencv_core.FileStorage.READ);
 mfs.open("E:/test.xml", opencv_core.FileStorage.READ);
  opencv_core.FileNode mynode= new opencv_core.FileNode();
  mynode=mfs.get("test");
  opencv_core.read(mynode,mymat);
  mfs.release();
  org.bytedeco.javacpp.opencv_imgcodecs.imwrite("E:/matwritten.png",mymat); `
tehseenmayar commented 7 years ago

hello sir! i am working on a project in which i am trying to detect skin color in an image using opencv in java. i have detect the skin color area but the problem is that the detected skin color area is white but i want that area to be colored with skin color..here is my code

Mat hsv=new Mat();

Imgproc.cvtColor(srcHSV,hsv,Imgproc.COLOR_BGR2HSV);

Core.inRange(hsv,new Scalar(0,58,40),new Scalar(35,174,255),hsv);

please help me as i am new to opencv