c++ - Qt Creater, Mac OS X: Error: "Symbol(s) not found" when calling function from included header -
i'm newbie c++ , qt creator. while trying compile program using opencv 3.0.0, on qt creator 3.4.1, on mac os x 10.10.4 following errors:
atopencv.pro
qt += core gui greaterthan(qt_major_version, 4): qt += widgets target = qtopencv template = app sources += main.cpp\ mainwindow.cpp headers += mainwindow.h \ colordetector.h forms += mainwindow.ui qmake_macosx_deployment_target = 10.10 includepath += /usr/local/include/ libs += -l/usr/local/lib libs += -lopencv_core libs += -lopencv_imgproc libs += -lopencv_highgui libs += -lopencv_ml libs += -lopencv_video libs += -lopencv_features2d libs += -lopencv_calib3d libs += -lopencv_objdetect libs += -lopencv_flann libs += -lopencv_imgcodecs mainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include <opencv2/opencv.hpp> #include <qfiledialog> #include "colordetector.h" mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent), ui(new ui::mainwindow) { ui->setupui(this); ui->pushbutton_2->setenabled(false); } mainwindow::~mainwindow() { delete ui; } void mainwindow::on_pushbutton_clicked() { qstring filename = qfiledialog::getopenfilename(this, tr("open image"), ".", tr("image files (*.png *.jpg *.bmp)")); image= cv::imread(filename.toutf8().data()); if (image.data) { ui->pushbutton_2->setenabled(true); } } void mainwindow::on_pushbutton_2_clicked() { colordetector cdetect; cdetect.settargetcolor(230, 190, 130); cv::mat result1; double duration; duration= static_cast<double>(cv::gettickcount()); result1= cdetect.process(image); duration= static_cast<double>(cv::gettickcount()) - duration; duration /= cv::gettickfrequency(); std::cout <<"duration "<< duration << " second" << std::endl; cv::imshow("final", result1); } colordetector.h
if !defined colordetect #define colordetect #include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> class colordetector { private: // minimum acceptable distance int maxdist; // target color cv::vec3b target; // image containing color converted image cv::mat converted; bool uselab; // image containing resulting binary map cv::mat result; public: // empty constructor // default parameter initialization here colordetector() : maxdist(100), target(0,0,0), uselab(false) {} // constructor lab color space example colordetector(bool uselab) : maxdist(100), target(0,0,0), uselab(uselab) {} // full constructor colordetector(uchar blue, uchar green, uchar red, int mxdist=100, bool uselab=false): maxdist(mxdist), uselab(uselab) { // target color settargetcolor(blue, green, red); } // computes distance target color. int getdistancetotargetcolor(const cv::vec3b& color) const { return getcolordistance(color, target); } // computes city-block distance between 2 colors. int getcolordistance(const cv::vec3b& color1, const cv::vec3b& color2) const { return abs(color1[0]-color2[0])+ abs(color1[1]-color2[1])+ abs(color1[2]-color2[2]); // or: // return static_cast<int>(cv::norm<int,3>(cv::vec3i(color[0]-color2[0],color[1]-color2[1],color[2]-color2[2]))); // or: // cv::vec3b dist; // cv::absdiff(color,color2,dist); // return cv::sum(dist)[0]; } // processes image. returns 1-channel binary image. cv::mat process(const cv::mat &image); cv::mat operator()(const cv::mat &image) { cv::mat input; input = image; if (uselab) { // lab conversion cv::cvtcolor(image, input, cv_bgr2lab); } cv::mat output; // compute absolute difference target color cv::absdiff(input,cv::scalar(target),output); // split channels 3 images std::vector<cv::mat> images; cv::split(output,images); // add 3 channels (saturation might occurs here) output= images[0]+images[1]+images[2]; // apply threshold cv::threshold(output, // input image output, // output image maxdist, // threshold (must < 256) 255, // max value cv::thresh_binary_inv); // thresholding type return output; } // getters , setters // sets color distance threshold. // threshold must positive, otherwise distance threshold // set 0. void setcolordistancethreshold(int distance) { if (distance<0) distance=0; maxdist= distance; } // gets color distance threshold int getcolordistancethreshold() const { return maxdist; } // sets color detected void settargetcolor(uchar blue, uchar green, uchar red) { // bgr order target = cv::vec3b(blue, green, red); if (uselab) { // temporary 1-pixel image cv::mat tmp(1, 1, cv_8uc3); tmp.at<cv::vec3b>(0, 0) = cv::vec3b(blue, green, red); // converting target lab color space cv::cvtcolor(tmp, tmp, cv_bgr2lab); target = tmp.at<cv::vec3b>(0, 0); } } // sets color detected void settargetcolor(cv::vec3b color) { target= color; } // gets color detected cv::vec3b gettargetcolor() const { return target; } }; #endif compiler output
14:27:06: running steps project qtopencv... 14:27:06: configuration unchanged, skipping qmake step. 14:27:06: starting: "/usr/bin/make" /applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -wl,-syslibroot,/applications/xcode.app/contents/developer/platforms/macosx.platform/developer/sdks/macosx10.10.sdk -mmacosx-version-min=10.10 -wl,-rpath,/users/apple/qt5.4.2/5.4/clang_64/lib -o qtopencv.app/contents/macos/qtopencv main.o mainwindow.o moc_mainwindow.o -f/users/apple/qt5.4.2/5.4/clang_64/lib -l/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_flann -lopencv_imgcodecs -framework qtwidgets -framework qtgui -framework qtcore -framework diskarbitration -framework iokit -framework opengl -framework agl undefined symbols architecture x86_64: "colordetector::process(cv::mat const&)", referenced from: mainwindow::on_pushbutton_2_clicked() in mainwindow.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation) make: *** [qtopencv.app/contents/macos/qtopencv] error 1 14:27:06: process "/usr/bin/make" exited code 2. error while building/deploying project qtopencv (kit: desktop qt 5.4.2 clang 64bit) when executing step "make" 14:27:06: elapsed time: 00:00. what trying is: give color, find , nearby color (within threshold) in image, mask color in white. function contained in header file colorselection.h . please me!
undefined symbols architecture x86_64: "colordetector::process(cv::mat const&)
this telling implementation function colordetector::process can't found.
mainwindow::on_pushbutton_2_clicked() in mainwindow.o
and function being called in mainwindow::on_pushbutton_2_clicked()
you've declared in colordetector.h, either implementation missing in colordetector.cpp, or doesn't match definition declared in header.
Comments
Post a Comment