bliako has asked for the wisdom of the Perl Monks concerning the following question:
Esteemed Monks,
I wanted to experiment with calling OpenCV v4.1.2 C++-api functions from within Perl via Inline::CPP
I have encountered a couple of problems, the last of which is insurmountable to me.
The first problem is that OpenCV defines a seed(unsigned s) function in /usr/local/include/opencv4/opencv2/core.hpp which conflicts with Perl's seed macro. That can be overcome by adding #undef seed at the top of my CPP section (see https://github.com/Leont/libperl--/issues/5). Although it passes that, it's no good news at all.
The second problem is that OpenCV uses internally the namespace cv (e.g. /usr/local/include/opencv4/opencv2/core/cvdef.h) which conflicts with Perl's struct cv in perl5/CORE/sv.h.
Any ideas or is that the end of the road for my efforts?
CPAN module Cv has not been updated since 2013 and is based on a very outdated OpenCV C-api (it includes #include <opencv/cv.h>) which no longer exists in version 3 or 4 of OpenCV. Just mentioning that that's not an option ...
Here is a sample code
#!/usr/bin/perl use strict; use warnings; use Inline CPP => DATA => CCFLAGS => '-std=c++11', LIBS => '-L/usr/local/lib64 -lopencv_imgcodecs -lopencv_core', INC => '-I/usr/local/include/opencv4' ; my $scrabble_image = 'IMAGES/scrabble_board1.jpg'; my $x = scrabbler($scrabble_image); __END__ __CPP__ #undef seed #include <iostream> #include <stdexcept> #include <stdlib.h> #include <math.h> #include <unordered_map> #include <map> #include <opencv2/core/types_c.h> #include <opencv2/imgproc.hpp> #include <opencv2/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/features2d/features2d.hpp> int scrabbler(char *imname){ cv::Mat myInputImage = cv::imread(imname); int W = myInputImage.cols; int H = myInputImage.rows; std::cout << "read image '" << imname << "': W=" << W << ", H=" << + H << std::endl; return 1; }
Many thanks, bliako
Update: added corrected cv::imread to sample code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inline::CPP + OpenCV = problems
by bliako (Abbot) on Nov 20, 2019 at 00:10 UTC | |
by Anonymous Monk on Nov 20, 2019 at 12:48 UTC | |
by bliako (Abbot) on Nov 20, 2019 at 19:52 UTC | |
by syphilis (Archbishop) on Nov 20, 2019 at 23:18 UTC | |
by bliako (Abbot) on Nov 20, 2019 at 23:41 UTC | |
|