Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error: Undefined References

I am trying to obtain mouse coordinates on hover and click in c++, The code i use is following:

include <opencv2 imgproc="" imgproc.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <stdio.h>

using namespace cv;

Mat img;

void onMouse(int event, int x, int y, int flags, void* param) { char text[100]; Mat img2, img3;

img2 = img.clone();

if (event == CV_EVENT_LBUTTONDOWN)
{
    Vec3b p = img2.at<Vec3b>(y,x);
    sprintf(text, "R=%d, G=%d, B=%d", p[2], p[1], p[0]);
}
else if (event == CV_EVENT_RBUTTONDOWN)
{
    cvtColor(img, img3, CV_BGR2HSV);
    Vec3b p = img3.at<Vec3b>(y,x);
    sprintf(text, "H=%d, S=%d, V=%d", p[0], p[1], p[2]);
}
else
    sprintf(text, "x=%d, y=%d", x, y);

putText(img2, text, Point(5,15), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0,255,0));
imshow("image", img2);

}

int main(int argc, char** argv) { img = imread(argc == 2 ? argv[1] : "lena.jpg"); if (img.empty()) return -1;

namedWindow("image");
setMouseCallback("image", onMouse, 0);
imshow("image", img);
waitKey(0);

return 0;

}

But I am getting many errors..

C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to cv::_OutputArray::_OutputArray(cv::Mat&)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference tocv::_InputArray::_InputArray(cv::Mat const&)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference tocv::putText(cv::Mat&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference tocv::imshow(std::string const&, cv::_InputArray const&)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to cv::imread(std::string const&, int)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference tocv::namedWindow(std::string const&, int)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to cv::setMouseCallback(std::string const&, void (*)(int, int, int, int, void*), void*)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference tocv::_InputArray::_InputArray(cv::Mat const&)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference tocv::waitKey(int)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x2b)||undefined reference to cv::fastFree(void*)'| (cv::Mat const&)]+0xfe)||undefined reference tocv::Mat::copySize(cv::Mat const&)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp:(.text$_ZNK2cv3Mat5cloneEv[cv::Mat::clone() const]+0x61)||undefined reference to cv::_OutputArray::_OutputArray(cv::Mat&)'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp:(.text$_ZNK2cv3Mat5cloneEv[cv::Mat::clone() const]+0x73)||undefined reference tocv::Mat::copyTo(cv::_OutputArray const&) const'| C:\Users\NAVIGATOR\Desktop\t.o:t.cpp:(.text$_ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x3c)||undefined reference to `cv::Mat::deallocate()'| ||=== Build failed: 17 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

I dont know how to deal with it. I have read something about changing makefile, but I am not getting it. I have checked, all the required directories are added to compiler. I am using codeblocks 13.12

Any assistance would be greatful.

Error: Undefined References

I am trying to obtain mouse coordinates on hover and click in c++, The code i use is following:

include <opencv2 imgproc="" imgproc.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <stdio.h>

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>

using namespace cv;

cv; Mat img;

img; void onMouse(int event, int x, int y, int flags, void* param) { char text[100]; Mat img2, img3;

img3;
img2 = img.clone();
 if (event == CV_EVENT_LBUTTONDOWN)
 {
  Vec3b p = img2.at<Vec3b>(y,x);
  sprintf(text, "R=%d, G=%d, B=%d", p[2], p[1], p[0]);
 }
 else if (event == CV_EVENT_RBUTTONDOWN)
 {
  cvtColor(img, img3, CV_BGR2HSV);
  Vec3b p = img3.at<Vec3b>(y,x);
  sprintf(text, "H=%d, S=%d, V=%d", p[0], p[1], p[2]);
 }
 else
  sprintf(text, "x=%d, y=%d", x, y);
 putText(img2, text, Point(5,15), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0,255,0));
 imshow("image", img2);

}

} int main(int argc, char** argv) { img = imread(argc == 2 ? argv[1] : "lena.jpg"); if (img.empty()) return -1;

-1;
namedWindow("image");
 setMouseCallback("image", onMouse, 0);
 imshow("image", img);
 waitKey(0);
 return 0;
}

}

But I am getting many errors..

C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to

cv::_OutputArray::_OutputArray(cv::Mat&)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference tocv::_InputArray::_InputArray(cv::Mat const&)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to cv::cvtColor(cv::_InputArray C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference tocv::putText(cv::Mat&, to `cv::putText(cv::Mat&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference tocv::imshow(std::string `cv::_InputArray::_InputArray(cv::Mat const&)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to cv::imread(std::string `cv::imread(std::string const&, int)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference tocv::namedWindow(std::string to `cv::namedWindow(std::string const&, int)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to cv::setMouseCallback(std::string `cv::setMouseCallback(std::string const&, void (*)(int, int, int, int, void*), void*)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference tocv::_InputArray::_InputArray(cv::Mat const&)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to cv::imshow(std::string to `cv::_InputArray::_InputArray(cv::Mat const&)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp|| undefined reference tocv::waitKey(int)'|
to `cv::waitKey(int)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x2b)||undefined reference to cv::fastFree(void*)'|
`cv::fastFree(void*)'|
(cv::Mat const&)]+0xfe)||undefined reference tocv::Mat::copySize(cv::Mat to `cv::Mat::copySize(cv::Mat const&)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp:(.text$_ZNK2cv3Mat5cloneEv[cv::Mat::clone() const]+0x61)||undefined reference to cv::_OutputArray::_OutputArray(cv::Mat&)'|
`cv::_OutputArray::_OutputArray(cv::Mat&)'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp:(.text$_ZNK2cv3Mat5cloneEv[cv::Mat::clone() const]+0x73)||undefined reference tocv::Mat::copyTo(cv::_OutputArray to `cv::Mat::copyTo(cv::_OutputArray const&) const'|
C:\Users\NAVIGATOR\Desktop\t.o:t.cpp:(.text$_ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x3c)||undefined reference to `cv::Mat::deallocate()'|
||=== Build failed: 17 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

===|

I dont know how to deal with it. I have read something about changing makefile, but I am not getting it. I have checked, all the required directories are added to compiler. I am using codeblocks 13.12

Any assistance would be greatful.