#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <stdio.h>
#include <stdlib.h>
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
vector<Rect> detectLetters(Mat img)
{
vector<Rect> boundRect;
Mat img_gray, img_sobel, img_threshold, element, img_dilated, img_denoised;
cvtColor(img, img_gray, CV_BGR2GRAY); // converting to gray scale
fastNlMeansDenoising(img_gray, img_denoised, 3, 7, 21);
Sobel(img_denoised, img_sobel, CV_8U, 1, 0, 3, 1, 0, BORDER_DEFAULT); // sobel is a differentiation function. this is used to find gradients
//dilate(img_sobel,img_dilated, Mat(),Point(-1,-1),1);
//adaptiveThreshold(img_sobel,img_threshold, 255, 0, THRESH_BINARY, 3,0);
threshold(img_sobel, img_threshold, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU); //
element = getStructuringElement(MORPH_RECT, Size(17, 3));
morphologyEx(img_threshold, img_threshold, CV_MOP_CLOSE, element); //Does the trick
vector<vector<Point>> contours;
findContours(img_threshold, contours, 0, 1);
vector<vector<Point> > contours_poly( contours.size() );
for( int i = 0; i < contours.size(); i++ )
if (contours[i].size()>100)
{
approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
Rect appRect( boundingRect( Mat(contours_poly[i]) ));
if (appRect.width>appRect.height)
boundRect.push_back(appRect);
}
imwrite( "img_gray.jpg", img_gray);
imwrite( "img_sobel.jpg", img_sobel);
imwrite( "img_threshold.jpg", img_threshold);
imwrite( "element.jpg", element);
return boundRect;
}
int main(int argc,char** argv)
{
//Read
Mat img1=imread(argv[1], 1);
Mat img2=imread(argv[2], 1);
//Detect
vector<Rect> letterBBoxes1=detectLetters(img1);
vector<Rect> letterBBoxes2=detectLetters(img2);
//Display
for(int i=0; i< letterBBoxes1.size(); i++)
rectangle(img1,letterBBoxes1[i],Scalar(0,255,0),3,8,0);
imwrite( "imgOut1_new.jpg", img1);
for(int i=0; i< letterBBoxes2.size(); i++)
rectangle(img2,letterBBoxes2[i],Scalar(0,255,0),3,8,0);
imwrite( "imgOut2_new.jpg", img2);
return 0;
}
I am getting the error
error LNK2019: unresolved external symbol "void __cdecl cv::fastNlMeansDenoising(class cv::_InputArray const &,class cv::_OutputArray const &,float,int,int)" (?fastNlMeansDenoising@cv@@YAXABV_InputArray@1@ABV_OutputArray@1@MHH@Z) referenced in function "class std::vector<class cv::Rect_<int>,class std::allocator<class cv::Rect_<int> > > __cdecl detectLetters(class cv::Mat)" (?detectLetters@@YA?AV?$vector@V?$Rect_@H@cv@@V?$allocator@V?$Rect_@H@cv@@@std@@@std@@VMat@cv@@@Z)
In my code, when I am removing fastNlMeansDenoising() function, the error is removed.
Can anyone explain what the problem is in this function??