Hi, i am a newbie in OpenCV world. My code snippet is shown below.
Mat CWaterFill::ContourFilter(Mat Img, int minSize) { int maxValue = 255; CvMemStorage* m_storage; m_storage = cvCreateMemStorage(0);
int m_region_count = 0;
CvSeq *m_first_seq = NULL;
CvSeq *m_prev_seq = NULL;
CvSeq *m_seq = NULL;
Mat ppp = Img;
cvMorphologyEx(ppp, ppp, 0, 0, CV_MOP_OPEN, 1);
cvMorphologyEx(ppp, ppp, 0, 0, CV_MOP_CLOSE, 1);
cvClearMemStorage(m_storage);
findContours(ppp, m_storage, &m_first_seq, sizeof(CvContour), CV_RETR_LIST);
for (m_seq = m_first_seq; m_seq; m_seq = m_seq->h_next)
{
CvContour* cnt = (CvContour*)m_seq;
if (cnt->rect.width * cnt->rect.height < minSize)
{
//delete small contour
m_prev_seq = m_seq->h_prev;
if (m_prev_seq)
{
m_prev_seq->h_next = m_seq->h_next;
if (m_seq->h_next) m_seq->h_next->h_prev = m_prev_seq;
}
else
{
m_first_seq = m_seq->h_next;
if (m_seq->h_next) m_seq->h_next->h_prev = NULL;
}
}
else
{
m_region_count++;
}
}
cvZero(ppp);
drawContours(ppp, m_first_seq, CV_RGB(0, 0, maxValue), CV_RGB(0, 0, maxValue), 10, -1);
Mat ipl = ppp;
cv::Mat ppp1 = ipl;
cvReleaseMemStorage(&m_storage);
return ppp1;
}
When I run the code the following error shows :
14:44:39 * Incremental Build of configuration Release for project DisplayImage * make all Building file: ../Main.cpp Invoking: GCC C++ Compiler g++ -I/usr/local/Cellar/opencv/3.4.1_4/include -O3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"Main.d" -MT"Main.o" -o "Main.o" "../Main.cpp" In file included from ../Main.cpp:2: ../WaterFill.h:11:13: warning: extra tokens at end of #pragma once directive [-Wextra-tokens]
pragma once;
^
//
../Main.cpp:50:2: error: no matching function for call to 'findContours' findContours(pp, m_storage, &m_first_seq, sizeof(CvContour), CV_RETR_LIST); ^~~~~~~~~~~~ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/imgproc.hpp:3899:19: note: candidate function not viable: no known conversion from 'CvMemStorage ' to 'const cv::_OutputArray' for 2nd argument CV_EXPORTS_W void findContours( InputOutputArray image, OutputArrayOfArrays contours, ^ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/imgproc.hpp:3904:17: note: candidate function not viable: no known conversion from 'CvMemStorage *' to 'const cv::_OutputArray' for 2nd argument CV_EXPORTS void findContours( InputOutputArray image, OutputArrayOfArrays contours, ^ ../Main.cpp:90:2: error: no matching function for call to 'findContours' findContours(pp, m_storage, &m_first_seq, sizeof(CvContour), CV_RETR_LIST); ^~~~~~~~~~~~ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/imgproc.hpp:3899:19: note: candidate function not viable: no known conversion from 'CvMemStorage *' to 'const cv::_OutputArray' for 2nd argument CV_EXPORTS_W void findContours( InputOutputArray image, OutputArrayOfArrays contours, ^ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/imgproc.hpp:3904:17: note: candidate function not viable: no known conversion from 'CvMemStorage *' to 'const cv::_OutputArray' for 2nd argument CV_EXPORTS void findContours( InputOutputArray image, OutputArrayOfArrays contours, ^ ../Main.cpp:91:31: error: no viable conversion from 'cv::Mat' to 'const CvArr *' (aka 'const void *') cv::Mat mpp = cv::cvarrToMat(pp); ^~ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/core/mat.hpp:1629:28: note: candidate template ignored: could not match 'vector<type-parameter-0-0, allocator<type-parameter-0-0=""> >' against 'const void *' template<typename _tp=""> operator std::vector<_Tp>() const; ^ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/core/mat.hpp:1630:35: note: candidate template ignored: could not match 'Vec<type-parameter-0-0, cn="">' against 'const void *' template<typename _tp,="" int="" n=""> operator Vec<_Tp, n>() const; ^ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/core/mat.hpp:1631:42: note: candidate template ignored: could not match 'Matx<type-parameter-0-0, m,="" n="">' against 'const void *' template<typename _tp,="" int="" m,="" int="" n=""> operator Matx<_Tp, m, n>() const; ^ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/core/mat.hpp:1634:45: note: candidate template ignored: could not match 'array<type-parameter-0-0, _size="">' against 'const void *' template<typename _tp,="" std::size_t="" _nm=""> operator std::array<_Tp, _Nm>() const; ^ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/core/core_c.h:2798:40: note: passing argument to parameter 'arr' here CV_EXPORTS Mat cvarrToMat(const CvArr arr, bool copyData=false, ^ ../Main.cpp:212:2: error: no matching function for call to 'cvMorphologyEx' cvMorphologyEx(ppp, ppp, 0, 0, CV_MOP_OPEN, 1); ^~~~~~~~~~~~~~ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/imgproc/imgproc_c.h:353:14: note: candidate function not viable: no known conversion from 'cv::Mat' to 'const CvArr ' (aka 'const void *') for 1st argument; take the address of the argument with & CVAPI(void) cvMorphologyEx( const CvArr src, CvArr* dst, ^ ../Main.cpp:213:2: error: no matching function for call to 'cvMorphologyEx' cvMorphologyEx(ppp, ppp, 0, 0, CV_MOP_CLOSE, 1); ^~~~~~~~~~~~~~ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/imgproc/imgproc_c.h:353:14: note: candidate function not viable: no known conversion from 'cv::Mat' to 'const CvArr ' (aka 'const void *') for 1st argument; take the address of the argument with & CVAPI(void) cvMorphologyEx( const CvArr src, CvArr* dst, ^ ../Main.cpp:216:2: error: no matching function for call to 'findContours' findContours(ppp, m_storage, &m_first_seq, sizeof(CvContour), CV_RETR_LIST); ^~~~~~~~~~~~ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/imgproc.hpp:3899:19: note: candidate function not viable: no known conversion from 'CvMemStorage *' to 'const cv::_OutputArray' for 2nd argument CV_EXPORTS_W void findContours( InputOutputArray image, OutputArrayOfArrays contours, ^ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/imgproc.hpp:3904:17: note: candidate function not viable: no known conversion from 'CvMemStorage *' to 'const cv::_OutputArray' for 2nd argument CV_EXPORTS void findContours( InputOutputArray image, OutputArrayOfArrays contours, ^ ../Main.cpp:242:2: error: no matching function for call to 'cvSetZero' cvZero(ppp); ^~~~~~ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/core/core_c.h:980:17: note: expanded from macro 'cvZero'
define cvZero cvSetZero
^~~~~~~~~
/usr/local/Cellar/opencv/3.4.1_4/include/opencv2/core/core_c.h:979:14: note: candidate function not viable: no known conversion from 'cv::Mat' to 'CvArr ' (aka 'void *') for 1st argument; take the address of the argument with & CVAPI(void) cvSetZero( CvArr arr ); ^ ../Main.cpp:243:2: error: no matching function for call to 'drawContours' drawContours(ppp, m_first_seq, CV_RGB(0, 0, maxValue), CV_RGB(0, 0, maxValue), 10, -1); ^~~~~~~~~~~~ /usr/local/Cellar/opencv/3.4.1_4/include/opencv2/imgproc.hpp:4648:19: note: candidate function not viable: no known conversion from 'CvSeq ' to 'const cv::_InputArray' for 2nd argument CV_EXPORTS_W void drawContours( InputOutputArray image, InputArrayOfArrays contours, ^ 1 warning and 8 errors generated. make: ** [Main.o] Error 1
14:44:41 Build Finished (took 2s.31ms)
I am using OpenCV in eclipse fr Mac