Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCV 3.1 DNN Module #145

Closed
paolobolettieri opened this issue Feb 4, 2016 · 19 comments
Closed

OpenCV 3.1 DNN Module #145

paolobolettieri opened this issue Feb 4, 2016 · 19 comments

Comments

@paolobolettieri
Copy link

A simple question: do the OpenCV presets include the new OpenCV 3.1 Deep Neural Network (DNN) module?
Thanks,

@saudet
Copy link
Member

saudet commented Feb 5, 2016

No, but it shouldn't be too hard to add. Would you like to make contribution?

@paolobolettieri
Copy link
Author

I could try, but I have to talk to my team leader. In the meanwhile, can you tell me please where I can find the JavaCPP docs? The only one I found is on https://github.com/bytedeco/javacpp. Is it enough?

@saudet
Copy link
Member

saudet commented Feb 8, 2016

I would suggest starting here:
https://github.com/bytedeco/javacpp-presets/wiki/Create-New-Presets
But in this case, we'd just basically need to copy, say, this file:
https://github.com/bytedeco/javacpp-presets/blob/master/opencv/src/main/java/org/bytedeco/javacpp/presets/opencv_optflow.java
Modify the settings for opencv_dnn, and it might very well work. If not, we may need to add a couple of Info, but that should be it.

@paolobolettieri
Copy link
Author

Hello, I'm trying to create the dnn presets with the code below, but I'm getting the following error

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project opencv: Compilation failure
opencv_dnn.java:[558,32] expected

The row 558 is the following

public native @ByVal cv::Ptr<Layer> call(@ByRef LayerParams params);

It seems a problem with this typedef in layer.hpp

typedef Ptr<Layer>(*Constuctor)(LayerParams &params);

Maybe a Info could solve it. Any suggestions?
Thanks.

@Properties(inherit = {opencv_core.class}, value = {
    @Platform(include = {"<opencv2/dnn.hpp>", "<opencv2/dnn/dict.hpp>","<opencv2/dnn/blob.hpp>", "<opencv2/dnn/layer.hpp>", "<opencv2/dnn/dnn.hpp>"}, link = "opencv_dnn@.3.1"),
    @Platform(value = "windows", link = "opencv_dnn310")},
        target = "org.bytedeco.javacpp.opencv_dnn")
public class opencv_dnn implements InfoMapper {
    public void map(InfoMap infoMap) {
    }
}

@paolobolettieri
Copy link
Author

Ok, the bug has been fixed, thanks.
Now I'm getting the following error:

jniopencv_dnn.cpp(2533) : error C2664: 'void cv::dnn::Layer::allocate(const std::vector> &,std::vectorcv::dnn::Blob,std::allocator<_Ty> &)': Cannot convert argument 1 from 'VectorAdaptercv::dnn::Blob,P' to 'const std::vector> &'
with
[
_Other=cv::dnn::Blob *
, _Ty=cv::dnn::Blob
]
and
[
P=cv::dnn::Blob
]
and
[
_Other=cv::dnn::Blob *
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be call

@saudet
Copy link
Member

saudet commented Feb 11, 2016

Like I said in a comment that seems to have been deleted for some reason, we're going to need to define a BlobVector like done for caffe here:
https://github.com/bytedeco/javacpp-presets/blob/master/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java#L137

@paolobolettieri
Copy link
Author

Done! But unfortunately there is a new problem :-(

jniopencv_dnn.obj : error LNK2001: unresolved external symbol "public: void __cdecl cv::dnn::Blob::fill(class cv::_InputArray const &)" (?fill@Blob@dnn@cv@@QEAAXAEBV_InputArray@3@@Z) unresolved
jniopencv_dnn.obj : error LNK2001: unresolved external symbol "class cv::dnn::Blob __cdecl cv::dnn::readTorchBlob(class cv::String const &,bool)" (?readTorchBlob@dnn@cv@@YA?AVBlob@12@AEBVString@2@_N@Z) unresolved
...

@saudet
Copy link
Member

saudet commented Feb 12, 2016

I don't have such problems on Linux. It looks like it doesn't support Windows yet... Could you ask the authors about that? Thanks!

@saudet
Copy link
Member

saudet commented Feb 13, 2016

Ah, no, this isn't a problem with Windows. These functions are simply not defined:

libjniopencv_dnn.so: undefined reference to `cv::dnn::Net::forwardOpt(cv::dnn::DictValue)'
libjniopencv_dnn.so: undefined reference to `cv::dnn::Net::setParam(cv::dnn::DictValue, int, cv::dnn::Blob const&)'
libjniopencv_dnn.so: undefined reference to `cv::dnn::readTorchBlob(cv::String const&, bool)'
libjniopencv_dnn.so: undefined reference to `cv::dnn::Net::forward(cv::dnn::DictValue, cv::dnn::DictValue)'
libjniopencv_dnn.so: undefined reference to `cv::dnn::Blob::fill(cv::_InputArray const&)'

So, we're going to need to add new Info(...).skip() for those to get this working on Windows. Unless the authors of DNN would be so kind to fix their code for us. :)

@paolobolettieri
Copy link
Author

Great!, I built it.
In the next days I'll check if it works (fine ;-))

@saudet
Copy link
Member

saudet commented Feb 14, 2016

Great! Please send a pull request when done! Thanks

@paolobolettieri
Copy link
Author

Hello,
DNN module works fine!!!
I just need a (last) little help. I'm not able to just skip the five non-defined functions.

For example, to skip
cv::dnn::Net::forward(cv::dnn::DictValue, cv::dnn::DictValue)

I set
infoMap.put(new Info("cv::dnn::Net::forward").skip())

but it skips all 'forward' functions and not only the needed one.
Also, I tried the following one

infoMap.put(new Info("cv::dnn::Net::forward(cv::dnn::DictValue, cv::dnn::DictValue)").skip())

but it doesn't work.
Could you help me, please?
Thanks

@saudet
Copy link
Member

saudet commented Feb 17, 2016

Yeah the Parser isn't so great here. Try to remove the space after the comma. That should work.

@paolobolettieri
Copy link
Author

Unfortunately it doesn't work :(
I'm only able to skip fill
infoMap.put(new Info("cv::dnn::Blob::fill(cv::InputArray)").skip());
Any other suggestions?

@ProjectsRebository
Copy link

can i create iris detection using javacv please help?

@saudet
Copy link
Member

saudet commented Feb 20, 2016

Ok, I've committed some presets that should work. Enjoy!

@paolobolettieri
Copy link
Author

Thank you!
In the meanwhile, I wrote the JavaCV version of the following OpenCV DNN example

http://docs.opencv.org/3.1.0/d5/de7/tutorial_dnn_googlenet.html#gsc.tab=0

It might be useful to someone. I can commit it on github if you agree on this.

@saudet
Copy link
Member

saudet commented Feb 25, 2016

That would be great, thanks! If it's simple enough and fits in one Java file + small data, please send a pull request for the samples directory here:
https://github.com/bytedeco/javacv/tree/master/samples
If you'd like to contribute a sample project instead, please send a pull request here:
https://github.com/bytedeco/sample-projects
Thank you!

@saudet
Copy link
Member

saudet commented May 19, 2016

Included in the newly released version 1.2. Enjoy!

@saudet saudet closed this as completed May 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants