Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
C++

XML
#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
VB
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??
Posted

1 solution

It is a linker problem, which means that the declared function isnt available for the linking stage. You must inlcude the implementatiion (file) of this function or add the lib to linked libraries. (Possible a namespace issue?)
 
Share this answer
 
Comments
Member 11721565 28-May-15 7:16am    
Any idea what library does it use? I had added all libraries while configuring openCV with the VS2010
Member 11721565 28-May-15 7:31am    
Thank you very much. From where I had copy pasted the linker libraries, a few had been missed. After updating, that error is gone.

Thanks.
CPallini 28-May-15 7:55am    
5.
Sergey Alexandrovich Kryukov 28-May-15 11:40am    
Sure, a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900