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


In reply to Inline::CPP + OpenCV = problems by bliako

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.