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

ld: library not found for -lopencvcapi #1

Closed
F1r3Hydr4nt opened this issue May 2, 2019 · 26 comments
Closed

ld: library not found for -lopencvcapi #1

F1r3Hydr4nt opened this issue May 2, 2019 · 26 comments

Comments

@F1r3Hydr4nt
Copy link
Contributor

F1r3Hydr4nt commented May 2, 2019

Hey dude, thanks for the wrapper. I'm just coming to terms with D for the first time and in the README of your repository you state "Your build experience may vary. I also need help for automating this. "

I am building on OSX so I'm not sure how to get around my build error but I have put this in my dub.json:
"lflags": ["-L/Users/XXX/.dub/packages/opencvd-0.0.2/opencvd", "-lopencvcapi", "-lopencvcapi_contrib"],

And it seems to be finding the directory just fine (as if I intentionally mistype the directory it throws an error) so I'm wondering if you might have a quick solution? Sorry for making my poor intelligence an issue on your project :/

@F1r3Hydr4nt
Copy link
Contributor Author

F1r3Hydr4nt commented May 2, 2019

I got it to pass that point by linking directly to the repo build folder (rather than the .dub/packages folder) but now it's having problems location -lopencv
ld: library not found for -lopencv

@aferust
Copy link
Owner

aferust commented May 2, 2019

Can you try -lopencv4.

@aferust
Copy link
Owner

aferust commented May 2, 2019

Do you have a pkgconfig file pointing to your opencv build?

@F1r3Hydr4nt
Copy link
Contributor Author

F1r3Hydr4nt commented May 2, 2019

You mean like this:
"lflags": ["-L/Users/XXX/Desktop/git-repos/d-tut/screentextparser/screentextparser/opencvd", "-lopencvcapi", "-lopencvcapi_contrib", "-lopencv4"],

This returns an error too unfortunately:
ld: library not found for -lopencv4

Thanks for the quick reply!

@F1r3Hydr4nt
Copy link
Contributor Author

No pkgconfig file, but maybe I should create one.. thanks!

@aferust
Copy link
Owner

aferust commented May 2, 2019

If you build and run any example code with success, can you please share your configuration* and steps to do it on OSX?
*: version of your c++ and d compilers, osx version, package manager (homebrew or macports?), opencv version.
And please use "git clone" the repo, don't use outdated dub repo, because I have just pushed some code to manage memory better. Thank you in advance!

@F1r3Hydr4nt
Copy link
Contributor Author

Yes ok cool I will, how do I go about adding an extra directory in the dub.json for -lopencv4 or -lopencv?

Like this?
lflags": ["-L/Users/XXX/Desktop/git-repos/d-tut/screentextparser/screentextparser/opencvd", "-lopencvcapi", "-lopencvcapi_contrib", "-L/installation/OpenCV-/lib/cmake/opencv4","-lopencv4" ?

@aferust
Copy link
Owner

aferust commented May 2, 2019

I ve just booted my pc from ubuntu partition. this is my exact and entire dub.json for compiling my tests:

{
"description": "A minimal D application.",
"dependencies": {
"opencvd": "0.0.2"
},
"authors": [
"Ferhat Kurtulmuş"
],
"copyright": "Copyright © 2019, Ferhat Kurtulmuş",
"license": "Boost",
"name": "mytest",
"importPaths": ["source"],
"sourcePaths": ["source"],
"lflags": ["-L/home/user/.dub/packages/opencvd", "-lopencvcapi", "-lopencvcapi_contrib"]
}

and there are copies of both libopencvcapi.a and libopencvcapi_contrib.a in the root folder of mytest app (right next to dub.json). While building opencv from source I forgot adding a cmake flag to generate a pkgconfig file so I created one in /usr/lib/pkgconfig/opencv.pc like:

prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: opencv
Description: OpenCv library
Version: 4.0.0
Cflags: -I${includedir}/opencv4
Libs: -L${libdir} -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs <there should be many more!>

These are enough for linux. But I have never tried it on OSX. It's been some time since I touched a mac. And the idea is that in opencvd's dub.json there is a key "libs-posix": ["opencv", "opencvcapi", "opencvcapi_contrib"]. I assume that this covers osx also (I am not sure if libs-osx or libs-mac are also valid keys). In this key, "opencv" value is handled by pkgconfig. so, if you have opencv4.pc file in /usr/lib/pkgconfig/ then it should be "opencv4". Thats what I know so far.

@F1r3Hydr4nt
Copy link
Contributor Author

This is slowly killing me, I might just program in C++ or install Linux :(

Eventually, after not being able to find opencv(4).pc I installed opencv with homebrew then I could find it in: /usr/local/lib/pkgconfig/opencv4.pc
And also in:
/usr/local/Cellar/opencv/4.1.0_1/lib/pkgconfig/opencv4.pc

But, alas, I have no idea how to link to it in the dub.json file :(

@aferust
Copy link
Owner

aferust commented May 3, 2019

I could find access to a mac temporarily. I am building opencv now. I will try to run an example, and report my experience soon.

@jacob-carlborg
Copy link

Look in the /usr/local/lib directory. Do you have any .a or .dylib files related to opencv? In that case add to the libs property in dub.json, the name of the library without the file extension and without the lib prefix, something like: "libs": ["opencv4"]. Then add this to the lflags property: "lflags": ["-L/usr/local/lib"].

@aferust
Copy link
Owner

aferust commented May 3, 2019

I have successfully compiled and run a test example on Sierra 10.12.5. I followed opencv build guide from https://www.learnopencv.com/install-opencv-4-on-macos/. I skipped the steps related with python and virtual env. Please note that this guide doesn't install opencv to the systems locations. My cmake command was like:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D OPENCV_GENERATE_PKGCONFIG=ON -D CMAKE_INSTALL_PREFIX=$cwd/installation/OpenCV-"$cvVersion" -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D WITH_TBB=ON -D WITH_V4L=ON -D OPENCV_SKIP_PYTHON_LOADER=ON -D CMAKE_PREFIX_PATH=$QT5PATH -D CMAKE_MODULE_PATH="$QT5PATH"/lib/cmake -D WITH_QT=ON -D WITH_OPENGL=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D BUILD_EXAMPLES=ON ..
after "make install" my opencv build is located in /Users/user/opencv4-dev/installation/OpenCV-master/. This folder includes bin, include, lib, and share folders.

I installed dub and ldc using homebrew.

Before compiling any code:

export PKG_CONFIG_PATH=/Users/user/opencv4-dev/installation/OpenCV-master/lib/pkgconfig/
export DYLD_LIBRARY_PATH=/Users/user/opencv4-dev/installation/OpenCV-master/lib/

Than build opencvcapi and opencvcapi_contrib using cmake and make commands following the ubuntu guide

replace this line in dub.json of opencvd:
"libs-posix": ["opencv", "opencvcapi", "opencvcapi_contrib"],
with
"libs-posix": ["opencv4", "opencvcapi", "opencvcapi_contrib"],

Copy libopencvcapi_contrib.a and libopencvcapi.a to the root of your example app. This is dub.json of example app:

{
	"description": "A minimal D application.",
    "dependencies": {
        "opencvd": "~>0.0.2"
	},
	"authors": [
		"Ferhat Kurtulmuş"
	],
	"copyright": "Copyright © 2019, Ferhat Kurtulmuş",
	"license": "Boost",
	"name": "testapp",
    "lflags": ["-L/Users/user/opencv4-dev/installation/OpenCV-master/lib/", "-L/Users/user/Desktop/testapp/"],
    "libs": [
        "opencv4",
        "opencvcapi",
        "opencvcapi_contrib",
    ]
}

@F1r3Hydr4nt
Copy link
Contributor Author

F1r3Hydr4nt commented May 7, 2019

Hey guys, thanks again for all the help (I've reinstalled OpenCV on OSX & also on a Devuan system) and the examples are running it's just the linking that I'm having problems with...

When you say above

Than build opencvcapi and opencvcapi_contrib using cmake and make commands following the ubuntu guide

Do you mean this part?

First, you have to compile C/C++ interface files:
cd opencvd/c && mkdir build
cd build
cmake ..
make // or cmake --build .
Then use dub to build the library.

Because as far as I can tell the very first long CMake command in your comment above includes the contrib directory!

@F1r3Hydr4nt
Copy link
Contributor Author

F1r3Hydr4nt commented May 7, 2019

screentextparser ~master: building configuration "application"... Linking... ld: library not found for -lopencv clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am still getting library not found :/
With my linker line in example application as follows:
"lflags": ["-L/Users/HON3D/Desktop/git-repos/d-tut/screentextparser/screentextparser/installation/OpenCV-master/lib"],

And the contents of that folder:

cmake libopencv_gapi.dylib libopencv_sfm.dylib libopencv_aruco.4.1.0.dylib libopencv_hfs.4.1.0.dylib libopencv_shape.4.1.0.dylib libopencv_aruco.4.1.dylib libopencv_hfs.4.1.dylib libopencv_shape.4.1.dylib libopencv_aruco.dylib libopencv_hfs.dylib libopencv_shape.dylib libopencv_bgsegm.4.1.0.dylib libopencv_highgui.4.1.0.dylib libopencv_stereo.4.1.0.dylib libopencv_bgsegm.4.1.dylib libopencv_highgui.4.1.dylib libopencv_stereo.4.1.dylib libopencv_bgsegm.dylib libopencv_highgui.dylib libopencv_stereo.dylib libopencv_bioinspired.4.1.0.dylib libopencv_img_hash.4.1.0.dylib libopencv_stitching.4.1.0.dylib libopencv_bioinspired.4.1.dylib libopencv_img_hash.4.1.dylib libopencv_stitching.4.1.dylib libopencv_bioinspired.dylib libopencv_img_hash.dylib libopencv_stitching.dylib libopencv_calib3d.4.1.0.dylib libopencv_imgcodecs.4.1.0.dylib libopencv_structured_light.4.1.0.dylib libopencv_calib3d.4.1.dylib libopencv_imgcodecs.4.1.dylib libopencv_structured_light.4.1.dylib libopencv_calib3d.dylib libopencv_imgcodecs.dylib libopencv_structured_light.dylib libopencv_ccalib.4.1.0.dylib libopencv_imgproc.4.1.0.dylib libopencv_superres.4.1.0.dylib libopencv_ccalib.4.1.dylib libopencv_imgproc.4.1.dylib libopencv_superres.4.1.dylib libopencv_ccalib.dylib libopencv_imgproc.dylib libopencv_superres.dylib libopencv_core.4.1.0.dylib libopencv_line_descriptor.4.1.0.dylib libopencv_surface_matching.4.1.0.dylib libopencv_core.4.1.dylib libopencv_line_descriptor.4.1.dylib libopencv_surface_matching.4.1.dylib libopencv_core.dylib libopencv_line_descriptor.dylib libopencv_surface_matching.dylib libopencv_cvv.4.1.0.dylib libopencv_ml.4.1.0.dylib libopencv_text.4.1.0.dylib libopencv_cvv.4.1.dylib libopencv_ml.4.1.dylib libopencv_text.4.1.dylib libopencv_cvv.dylib libopencv_ml.dylib libopencv_text.dylib libopencv_datasets.4.1.0.dylib libopencv_objdetect.4.1.0.dylib libopencv_tracking.4.1.0.dylib libopencv_datasets.4.1.dylib libopencv_objdetect.4.1.dylib libopencv_tracking.4.1.dylib libopencv_datasets.dylib libopencv_objdetect.dylib libopencv_tracking.dylib libopencv_dnn.4.1.0.dylib libopencv_optflow.4.1.0.dylib libopencv_video.4.1.0.dylib libopencv_dnn.4.1.dylib libopencv_optflow.4.1.dylib libopencv_video.4.1.dylib libopencv_dnn.dylib libopencv_optflow.dylib libopencv_video.dylib libopencv_dnn_objdetect.4.1.0.dylib libopencv_phase_unwrapping.4.1.0.dylib libopencv_videoio.4.1.0.dylib libopencv_dnn_objdetect.4.1.dylib libopencv_phase_unwrapping.4.1.dylib libopencv_videoio.4.1.dylib libopencv_dnn_objdetect.dylib libopencv_phase_unwrapping.dylib libopencv_videoio.dylib libopencv_dpm.4.1.0.dylib libopencv_photo.4.1.0.dylib libopencv_videostab.4.1.0.dylib libopencv_dpm.4.1.dylib libopencv_photo.4.1.dylib libopencv_videostab.4.1.dylib libopencv_dpm.dylib libopencv_photo.dylib libopencv_videostab.dylib libopencv_face.4.1.0.dylib libopencv_plot.4.1.0.dylib libopencv_xfeatures2d.4.1.0.dylib libopencv_face.4.1.dylib libopencv_plot.4.1.dylib libopencv_xfeatures2d.4.1.dylib libopencv_face.dylib libopencv_plot.dylib libopencv_xfeatures2d.dylib libopencv_features2d.4.1.0.dylib libopencv_quality.4.1.0.dylib libopencv_ximgproc.4.1.0.dylib libopencv_features2d.4.1.dylib libopencv_quality.4.1.dylib libopencv_ximgproc.4.1.dylib libopencv_features2d.dylib libopencv_quality.dylib libopencv_ximgproc.dylib libopencv_flann.4.1.0.dylib libopencv_reg.4.1.0.dylib libopencv_xobjdetect.4.1.0.dylib libopencv_flann.4.1.dylib libopencv_reg.4.1.dylib libopencv_xobjdetect.4.1.dylib libopencv_flann.dylib libopencv_reg.dylib libopencv_xobjdetect.dylib libopencv_freetype.4.1.0.dylib libopencv_rgbd.4.1.0.dylib libopencv_xphoto.4.1.0.dylib libopencv_freetype.4.1.dylib libopencv_rgbd.4.1.dylib libopencv_xphoto.4.1.dylib libopencv_freetype.dylib libopencv_rgbd.dylib libopencv_xphoto.dylib libopencv_fuzzy.4.1.0.dylib libopencv_saliency.4.1.0.dylib opencv4 libopencv_fuzzy.4.1.dylib libopencv_saliency.4.1.dylib pkgconfig libopencv_fuzzy.dylib libopencv_saliency.dylib python3.6 libopencv_gapi.4.1.0.dylib libopencv_sfm.4.1.0.dylib libopencv_gapi.4.1.dylib libopencv_sfm.4.1.dylib

@F1r3Hydr4nt
Copy link
Contributor Author

I think I'll just move over to Ubuntu and use this tutorial: https://www.learnopencv.com/install-opencv-4-on-ubuntu-18-04/

Thanks for all the help thus far in any case.

@aferust
Copy link
Owner

aferust commented May 7, 2019

I want to learn if you succeded to compile c api of opencvd located in "opencvd/c" using commands:

cd opencvd/c
mkdir build
cd build
cmake ..
make

I am sorry for asking. At some point, I cannot understand your situation, maybe due to my poor English. Meanwhile I changed dub.json on the git repo to be ""libs-posix": ["opencv4", "opencvcapi", "opencvcapi_contrib"]", please note that it is now "opencv4", not "opencv". And, sometimes when you change some configuration, you may need to manually delete .dub folder in root of both opencvd and your test app.
And I want to know if you successfully compile and run any example code in examples folder such as convexhull?

@F1r3Hydr4nt
Copy link
Contributor Author

Sure, I am using this script currently to install OpenCV: https://github.com/spmallick/learnopencv/blob/master/InstallScripts/installOpenCV-4-on-Ubuntu-18-04.sh

However, I added the flag which you gave me -D OPENCV_GENERATE_PKGCONFIG=ON \
Between line number 89 & 90 just to be certain I have an opencv(4).pc to point towards when it all compiles.

Hopefully it will work this time and I can report back when it does (or does not). Unfortunately OpenCV takes a long time to compile on this system, but I do want to be able to use D lang for the first time on this project.

Thanks again for all your help!

@F1r3Hydr4nt
Copy link
Contributor Author

F1r3Hydr4nt commented May 7, 2019

Ok, I was still having problems with the last line here:
cd opencvd/c mkdir build cd build cmake ..

The error is the same as before:
`Could not find a package configuration file provided by "OpenCV" with any
of the following names:

OpenCVConfig.cmake
opencv-config.cmake`

So I had to specify it directly to the cmake call (rather than export OpenCV_DIR=/...):
sudo cmake -DOpenCV_DIR=/home/dev/OpenCV/installation/OpenCV-master/lib/cmake/opencv4 ..

That worked so I could run the final make which built the opencvd/c/ folder and so I could go up one directory and run sudo dub build Performing "debug" build using /usr/bin/ldc2 for x86_64. opencvd 0.0.3: building configuration "library"... Copying files for opencvd..

Which also worked. So then in my example application I ran dub init, added opencvd as a package then, simply, to test I ran sudo dub build

But it failed with these errors:
/usr/bin/ld: cannot find -lopencv4 /usr/bin/ld: cannot find -lopencvcapi /usr/bin/ld: cannot find -lopencvcapi_contrib

So I went to the README.md and made the additions to the dub.json:
{ "name": "dimagetextreader", "authors": [ "Freddie Honohan" ], "dependencies": { "opencvd": "~>0.0.3" }, "lflags": ["-L/home/dev/.dub/packages/opencvd-0.0.3/opencvd/", "-lopencvcapi", "-lopencvcapi_contrib"], "libs": [ "opencv4", "opencvcapi", "opencvcapi_contrib", ], "description": "An OpenCV dependent Image Text Extractor written in D.", "copyright": "Copyright © 2019, Freddie Honohan", "license": "proprietary" }

But the build also failed again with the same error, so I changed the .dub/packages directory to point to the actual opencvd directory:
"lflags": ["-L/home/dev/Dlang/opencvd", "-lopencvcapi", "-lopencvcapi_contrib"],

And it removed 2 errors leaving only 1:
/usr/bin/ld: cannot find -lopencv4

So, FINALLY, after figuring out what was going on by running: pkg-config --variable pc_path pkg-config
It told me where my system was looking for ALL the pkgconfig files '.pc'

So I simply copied the opencv4.pc file over to one of those directories:
sudo cp /home/dev/OpenCV/installation/OpenCV-master/lib/pkgconfig/opencv4.pc /usr/lib/pkgconfig/.

And BOOM
~/Dlang/DImageTextReader$ sudo dub run Performing "debug" build using /usr/bin/ldc2 for x86_64. opencvd 0.0.3: target for configuration "library" is up to date. dimagetextreader ~master: target for configuration "application" is up to date. To force a rebuild of up-to-date targets, run again with --force. Copying files for opencvd... Running ./dimagetextreader Edit source/app.d to start your project.

But, unfortunately, when I copy the contents of opencvd/examples/convexhull.d into my example app.d and try to build it IT WORKS however when it runs I get an error:
~/Dlang/DImageTextReader$ sudo dub run --force Performing "debug" build using /usr/bin/ldc2 for x86_64. opencvd 0.0.3: building configuration "library"... dimagetextreader ~master: building configuration "application"... Copying files for opencvd... Running ./dimagetextreader ./dimagetextreader: error while loading shared libraries: libopencv_face.so.4.1: cannot open shared object file: No such file or directory Program exited with code 127

Which I am not sure about, can I run the examples from the opencvd folder directly? Perhaps I should test a bit more!

@F1r3Hydr4nt
Copy link
Contributor Author

F1r3Hydr4nt commented May 8, 2019

Ok, I got it all working thanks be to God!

I stumbled upon this unix command "ldconfig" from here: https://unix.stackexchange.com/questions/67781/use-shared-libraries-in-usr-local-lib
Which led me to this: https://linux.die.net/man/8/ldconfig

Finally I ran:
sudo ldconfig /home/dev/OpenCV/installation/OpenCV-master/lib/ -v

And my example app.d containing the convexhull.d code compiles and runs!
*It is worthwhile running a dub clean everytime!

Thanks a million, I hope this troubleshooting helps the project moving forward 👍

@aferust
Copy link
Owner

aferust commented May 8, 2019

Congrats, awesome news!

@aferust
Copy link
Owner

aferust commented May 8, 2019

Hey buddy, I guess you will do something like a text detection app. Here I put a working example https://github.com/aferust/opencvd/blob/master/examples/text_detection.d. You will need to update opencvd from master, since I ve just pushed some code to run it.

@F1r3Hydr4nt
Copy link
Contributor Author

Thanks man, could be handy, although I am using it for screenshots and somebody has mentioned it was not very good at screenshots here: https://www.pyimagesearch.com/2018/08/20/opencv-text-detection-east-text-detector/

I was using "dhanushka"'s answer from here: https://stackoverflow.com/questions/23506105/extracting-text-opencv/23557702
So far, however I had to write my own contour filtering loop because I could not figure out what they were doing with these lines:
Mat maskROI(mask, rect); maskROI = Scalar(0, 0, 0);
And OpenCV 4.X does not include that function maskROI, perhaps they just mean (in D) to create a Mat called maskROI from the inner rect of the mask Mat:
Mat maskROI = mask(rect);
But then I was lost, I don't really need that part anyway although it would be nice to be able to figure out the "ratio of non-zero pixels in the filled region" in order to discard regions without text!

@aferust
Copy link
Owner

aferust commented May 9, 2019

Mat maskROI(mask, rect); maskROI = Scalar(0, 0, 0); this can be done with opencvd like:

import opencvd.cvcore;
import opencvd.imgcodecs;
import opencvd.highgui;

import opencvd.ocvversion;

void main()
{
    Mat img = imread("test.png", 0);
    Rect r = {50, 50, 200, 200}; 
    Mat m = img(r);  // m is just a pointer to subimage of img sharing the same data in the memory. 
// setting all pixels of window r to white:
    m = Scalar(255,255,255); //  so, if you modify pixels of m, this means you are modifying windowed pixels of img in the same time.
    imshow("im", img); // see here that original image img was modified
    waitKey(0);
    
}

You can use int countNonZero(Mat src) to get non-zero pixels ratio like:

float ratio = float(m.countNonZero) / (float(m.rows)*float(m.cols)); I did not tested, but it should work.

I have also another project (regionpropsford) that can be used to calculate region properties in binary image (there is an example usage with opencvd on readme of it).

@F1r3Hydr4nt
Copy link
Contributor Author

F1r3Hydr4nt commented May 9, 2019

Thanks for this!

I have been enjoying this. There are opencv2 functions which are not exposed in your D wrapper (as far as I can tell). If you gave me brief instructions I could attempt to implement them (if possible). Then, if I accomplished that I could try expose the rest and make a pull request!

The two functions I was looking at but could not find in opencvd are: fastNlMeansDenoisingColored & createCLAHE
Respectively: https://docs.opencv.org/master/d6/dc7/group__imgproc__hist.html#gad689d2607b7b3889453804f414ab1018
And:
https://docs.opencv.org/4.1.0/d1/d79/group__photo__denoise.html#ga4c6b0031f56ea3f98f768881279ffe93

For example when I grep for the first in the opencvd directory:
~/Dlang/opencvd$ grep -r fastNlMeansDenoisingColored *

It returns no results however the second does:
~/Dlang/opencvd$ grep -r createCLAHE * c/imgproc.cpp: return new cv::Ptr<cv::CLAHE>(cv::createCLAHE()); c/imgproc.cpp: return new cv::Ptr<cv::CLAHE>(cv::createCLAHE(clipLimit, sz)); Binary file c/build/CMakeFiles/opencvcapi.dir/imgproc.cpp.o matches Binary file c/build/libopencvcapi.a matches Binary file libopencvcapi.a matches

I can help bring these into the library as payment for the help you have given me if you like? I do not even need them anymore to be frank!

If you could point towards something that's similarly exposed in opencvd I'm sure I'd be able to use it to translate more features.

👍

**I see neither of them are in the github.com/hybridgroup/gocv wrapper either unfortunately :(

@aferust
Copy link
Owner

aferust commented May 9, 2019

Ok, first of all, please share your email 'cause it is redundant to grow this page unnecessarily. You can search opencv function names using github's search in the project feature, although grep is also nice.
I started to this project borrowing gocv's c/cpp interface files, but I realized that they does not cover many opencv features as you stated. I did not want to modify the original cpp sources of gocv, so I started appending new code in files like:

  • if the new function is not available in imgproc.h/imgproc.cpp, simply I create imgproc_helper.h/imgproc_helper.cpp, and implement new function or type in those new files.
  • if gocv did not even wrap an opencv module, this time I create new files like photo_helper.h/photo_helper.cpp even though there is no photo.h/photo.cpp.
  • *.h files must not contain any cpp type or code, they must be just plain c declarations.
  • *.cpp files are implementations of opencv features, that may/must contain cpp code.
    For fastNlMeansDenoisingColored, things would be easy since it does not require wrapping a new opencv type (wrapping new types using opaque c pointers is a little more complicated, but I can explain it later). It is belong to photo_helper.h/photo_helper.cpp. I see that this function has 3 different overloads, and one is involved in cuda, so just skip it for now. Take the second overload and lets wrap it:
    void cv::fastNlMeansDenoising ( InputArray src, OutputArray dst, float h , int templateWindowSize, int searchWindowSize )

in photo_helper.cpp capitalize initial of the func name:

// I guess both src and dst are cv::Mat so
void FastNlMeansDenoising2 (Mat src, Mat dst, float h, int templateWindowSize,  int searchWindowSize){
    cv::FastNlMeansDenoising(*src, *dst, h, templateWindowSize, searchWindowSize); // does actual job.
}

I have named it FastNlMeansDenoising2, because I may wrap the first oveload in the future and just reserve the "FastNlMeansDenoising1".
#Note that cv::Mat is wrapped with void*. Since it is a pointer, we have to write vars like *src, *dst. If we had to access a member func or var of src, we would write "src->rows", "src->size" etc.
Anyway, now open photo_helper.h and add:
void FastNlMeansDenoising2 (Mat src, Mat dst, float h, int templateWindowSize, int searchWindowSize);
As you may notice that we have just ignored default parameters of the function. We will pass them on d side.

  • open source/photo.d and add the same definition in "private extern (C){" block.
private extern (C){
    ...
    void FastNlMeansDenoising2 (Mat src, Mat dst, float h, int templateWindowSize,  int searchWindowSize);
    ...
}
  • and in the source/photo.d, also add a d function (making its initial lowercase) which will call this c function:
// outside of extern block
 void fastNlMeansDenoising (Mat src, Mat dst, float h =3, int templateWindowSize = 7,  int searchWindowSize = 21){
     FastNlMeansDenoising2 (src, dst, h, templateWindowSize,  searchWindowSize);
}

As you can see, we have set default parameters in d function: "float h =3, int templateWindowSize = 7, int searchWindowSize = 21"

That's it.

@F1r3Hydr4nt
Copy link
Contributor Author

Ok perfect, there is no private message function on this is there?

Anyway, I will make an attempt at those two functions tomorrow morning and you can take my email from my next message, which I will delete!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants