Tôi đang sử dụng OpenCV2 trên Ubuntu 12.04. Tôi có thể chạy thành công mã hiển thị hình ảnh đọc. Tuy nhiên tôi không thể chạy mã với các chức năng sẵn có, ví dụ như. cvtColor()Opencv2 cvtColor() không hoạt động
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>
int main(int argc, char *argv[])
{
cv::Mat image = cv::imread("img.jpg");
if(image.data == NULL)
{
printf("file cannot be loaded\n");
return 1;
}
cv::namedWindow("My");
cv::imshow("My", image);
cv::Mat result;
cv::cvtColor(image, result, CV_BGR2Luv);
cv::imwrite("outImg.jpg", result);
cv::waitKey(0);
return 0;
}
Tôi đang sử dụng Qt-tác giả cho OpenCV tôi Sau khi biên dịch với --libs, --cflags tôi nhận được lỗi sau biên dịch:
make: Entering directory `/home/swaroop/Work/ai-junkies/cuda/uc_davis/opencv2.x/OpenCV2Test'
g++ -g -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I/usr/include/opencv -I. -o main.o main.cpp
main.cpp: In function 'int main(int, char**)':
main.cpp:22:29: error: 'CV_BGR2Luv' was not declared in this scope
main.cpp:22:39: error: 'cvtColor' was not declared in this scope
Xin hãy giúp tôi sửa lỗi này.
bạn là chính xác. Tôi phải #include. –
mkuse
Có cách nào dễ dàng để biết (không hỏi) các tệp tiêu đề nào cần bao gồm không? – PaulrBear