Skip to content

Commit de4d44a

Browse files
authored
opencv2.cfg: Add initial OpenCV 2.x API Library Configuration (#2439)
1 parent 40aefa1 commit de4d44a

5 files changed

Lines changed: 141 additions & 1 deletion

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ env:
2020
before_install:
2121
# install needed deps
2222
- travis_retry sudo apt-get update -qq
23-
- travis_retry sudo apt-get install -qq python3-pip qt5-default qt5-qmake qtbase5-dev qtcreator libxml2-utils libpcre3 gdb unzip wx-common xmlstarlet python3-dev liblua5.3-dev libcurl3 libcairo2-dev libsigc++-2.0-dev tidy
23+
- travis_retry sudo apt-get install -qq python3-pip qt5-default qt5-qmake qtbase5-dev qtcreator libxml2-utils libpcre3 gdb unzip wx-common xmlstarlet python3-dev liblua5.3-dev libcurl3 libcairo2-dev libsigc++-2.0-dev tidy libopencv-dev
2424
# Python 2 modules
2525
- travis_retry python2 -m pip install --user pytest==4.6.4
2626
- travis_retry python2 -m pip install --user pylint

cfg/opencv2.cfg

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0"?>
2+
<def format="2">
3+
<!-- OpenCV (Open Source Computer Vision Library) Library Configuration http://opencv.org) -->
4+
<!-- This configuration is for the OpenCV 2.x API (The C++ API, not the older C API) -->
5+
<!-- The OpenCV library is typically included by '#include <opencv2/*>' or -->
6+
<!-- '#include "opencv2/*"'. -->
7+
<!-- ########## OpenCV Types ########## -->
8+
<!-- ########## OpenCV Macros / Defines ########## -->
9+
<define name="CV_PI" value="3.1415926535897932384626433832795"/>
10+
<define name="CV_2PI" value="6.283185307179586476925286766559"/>
11+
<define name="CV_LOG2" value="0.69314718055994530941723212145818"/>
12+
<define name="CV_MAT_CN_MASK" value="((CV_CN_MAX - 1) &lt;&lt; CV_CN_SHIFT)"/>
13+
<define name="CV_MAT_CN(flags)" value="((((flags) &amp; CV_MAT_CN_MASK) &gt;&gt; CV_CN_SHIFT) + 1)"/>
14+
<define name="CV_MAT_TYPE_MASK" value="(CV_DEPTH_MAX*CV_CN_MAX - 1)"/>
15+
<define name="CV_MAT_TYPE(flags)" value="((flags) &amp; CV_MAT_TYPE_MASK)"/>
16+
<define name="CV_MAT_CONT_FLAG_SHIFT" value="14"/>
17+
<define name="CV_MAT_CONT_FLAG" value="(1 &lt;&lt; CV_MAT_CONT_FLAG_SHIFT)"/>
18+
<define name="CV_IS_MAT_CONT(flags)" value="((flags) &amp; CV_MAT_CONT_FLAG)"/>
19+
<define name="CV_IS_CONT_MAT" value="CV_IS_MAT_CONT"/>
20+
<define name="CV_SUBMAT_FLAG_SHIFT" value="15"/>
21+
<define name="CV_SUBMAT_FLAG" value="(1 &lt;&lt; CV_SUBMAT_FLAG_SHIFT)"/>
22+
<define name="CV_IS_SUBMAT(flags)" value="((flags) &amp; CV_MAT_SUBMAT_FLAG)"/>
23+
<define name="MIN(a,b)" value="((a) &gt; (b) ? (b) : (a))"/>
24+
<define name="MAX(a,b)" value="((a) &lt; (b) ? (b) : (a))"/>
25+
<!-- ########## OpenCV containers ########## -->
26+
<!-- OpenCV containers that are similar to std containers -->
27+
<container id="cvString" startPattern="cv :: String" inherits="stdString"/>
28+
<!-- ########## OpenCV Allocation / Deallocation ########## -->
29+
<!-- ########## OpenCV Functions ########## -->
30+
<!-- Mat cv::imread ( const String & filename, int flags = IMREAD_COLOR ) -->
31+
<function name="cv::imread">
32+
<noreturn>false</noreturn>
33+
<returnValue type="cv::Mat"/>
34+
<use-retval/>
35+
<arg nr="1" direction="in">
36+
<not-uninit/>
37+
</arg>
38+
<arg nr="2" direction="in" default="cv::IMREAD_COLOR">
39+
<not-uninit/>
40+
<not-bool/>
41+
</arg>
42+
</function>
43+
<!-- void cv::imshow ( const String & winname, InputArray mat ) -->
44+
<!-- void cv::imshow ( const String & winname, const ogl::Texture2D & tex ) -->
45+
<function name="cv::imshow">
46+
<noreturn>false</noreturn>
47+
<returnValue type="void"/>
48+
<arg nr="1" direction="in">
49+
<not-uninit/>
50+
</arg>
51+
<arg nr="2" direction="in">
52+
<not-uninit/>
53+
<not-bool/>
54+
</arg>
55+
</function>
56+
<!-- void cv::namedWindow ( const String & winname, int flags = WINDOW_AUTOSIZE ) -->
57+
<function name="cv::namedWindow">
58+
<noreturn>false</noreturn>
59+
<returnValue type="void"/>
60+
<arg nr="1" direction="in">
61+
<not-uninit/>
62+
</arg>
63+
<arg nr="2" direction="in" default="cv::WINDOW_AUTOSIZE">
64+
<not-uninit/>
65+
<not-bool/>
66+
</arg>
67+
</function>
68+
<!-- int cv::waitKey ( int delay = 0 ) -->
69+
<function name="cv::waitKey">
70+
<noreturn>false</noreturn>
71+
<returnValue type="int"/>
72+
<arg nr="1" direction="in" default="0">
73+
<not-uninit/>
74+
<not-bool/>
75+
</arg>
76+
</function>
77+
</def>

test/cfg/opencv2.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
// Test library configuration for opencv2.cfg
3+
//
4+
// Usage:
5+
// $ cppcheck --check-library --library=cairo --enable=information --error-exitcode=1 --inline-suppr --suppress=missingIncludeSystem test/cfg/opencv2.cpp
6+
// =>
7+
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
8+
//
9+
10+
#include <iostream>
11+
#include <opencv2/opencv.hpp>
12+
13+
14+
void validCode(char* argStr)
15+
{
16+
cv::Mat image;
17+
image = cv::imread(argStr, cv::IMREAD_COLOR);
18+
if (!image.data) {
19+
printf("No image data \n");
20+
return;
21+
}
22+
cv::namedWindow("Display Image", cv::WINDOW_AUTOSIZE);
23+
cv::imshow("Display Image", image);
24+
cv::waitKey(0);
25+
26+
cv::String cvStr("Hello");
27+
cvStr += " World";
28+
std::cout << cvStr;
29+
}
30+
31+
void ignoredReturnValue()
32+
{
33+
// cppcheck-suppress ignoredReturnValue
34+
cv::imread("42.png");
35+
}

test/cfg/runtests.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,33 @@ else
365365
fi
366366
${CPPCHECK} ${CPPCHECK_OPT} --library=openssl ${DIR}openssl.c
367367

368+
# opencv2.cpp
369+
set +e
370+
pkg-config --version
371+
PKGCONFIG_RETURNCODE=$?
372+
set -e
373+
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then
374+
echo "pkg-config needed to retrieve OpenCV configuration is not available, skipping syntax check."
375+
else
376+
set +e
377+
OPENCVCONFIG=$(pkg-config --cflags opencv)
378+
OPENCVCONFIG_RETURNCODE=$?
379+
set -e
380+
if [ $OPENCVCONFIG_RETURNCODE -eq 0 ]; then
381+
set +e
382+
echo -e "#include <opencv2/opencv.hpp>\n" | ${CXX} ${CXX_OPT} ${OPENCVCONFIG} -x c++ -
383+
OPENCVCONFIG_RETURNCODE=$?
384+
set -e
385+
if [ $OPENCVCONFIG_RETURNCODE -ne 0 ]; then
386+
echo "OpenCV not completely present or not working, skipping syntax check with ${CXX}."
387+
else
388+
echo "OpenCV found and working, checking syntax with ${CXX} now."
389+
${CXX} ${CXX_OPT} ${OPENCVCONFIG} ${DIR}opencv2.cpp
390+
fi
391+
fi
392+
fi
393+
${CPPCHECK} ${CPPCHECK_OPT} --library=opencv2 ${DIR}opencv2.cpp
394+
368395
# Check the syntax of the defines in the configuration files
369396
set +e
370397
xmlstarlet --version

tools/donate_cpu_lib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ def get_libraries():
460460
'microsoft_sal': ['<sal.h>'],
461461
'motif': ['<X11/', '<Xm/'],
462462
'nspr': ['<prtypes.h>', '"prtypes.h"'],
463+
# 'opencv2': ['<opencv2/', '"opencv2/'], <= enable after release of version 1.90
463464
'opengl': ['<GL/gl.h>', '<GL/glu.h>', '<GL/glut.h>'],
464465
'openmp': ['<omp.h>'],
465466
# 'openssl': ['<openssl/'], <= enable after release of version 1.90

0 commit comments

Comments
 (0)