我试图使用Qt Creator运行/调试OpenCV的简单示例,但没有成功
环境
Ubuntu 12.04(64位)
Qt Creator 3.0.0基于Qt 5.2.0(64位)
OpenCV 2.4.8
来源
的main.cpp
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
void help() {
cout <<"\nDemonstrate Canny edge detection\n"<< endl;
}
int edgeThresh = 1;
Mat image, gray, edge, cedge;
// define a trackbar callback
void onTrackbar(int, void*) {
blur(gray, edge, Size(3,3));
// Run the edge detector on grayscale
Canny(edge, edge, edgeThresh, edgeThresh*3, 3);
cedge = Scalar::all(0);
image.copyTo(cedge, edge);
imshow("Edge map", cedge);
}
int main( int argc, char** argv ) {
//QCoreApplication a(argc, argv);
char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
image = imread(filename, 1);
if(image.empty()) {
//help();
return -1;
}
help();
cedge.create(image.size(), image.type());
cvtColor(image, gray, CV_BGR2GRAY);
// Create a window
namedWindow("Edge map", 1);
// create a toolbar
createTrackbar("Canny threshold", "Edge map", &edgeThresh, 100, onTrackbar);
// Show the image
onTrackbar(0, 0);
// Wait for a key stroke; the same function arranges events processing
waitKey(0);
return 0;
//return a.exec();
}
FirstQtProject.pro
#-------------------------------------------------
#
# Project created by QtCreator 2014-01-13T22:34:52
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = FirstQtProject
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += "/usr/local/include/opencv2"
LIBS += `pkg-config --cflags --libs opencv`
构建信息
20:45:14: Running steps for project FirstQtProject...
20:45:14: Configuration unchanged, skipping qmake step.
20:45:14: Starting: "/usr/bin/make"
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_CORE_LIB -I../../Qt5.2.0/5.2.0/gcc_64/mkspecs/linux-g++ -I../FirstQtProject -I/usr/local/include/opencv2 -I../../Qt5.2.0/5.2.0/gcc_64/include -I../../Qt5.2.0/5.2.0/gcc_64/include/QtCore -I. -I. -o main.o ../FirstQtProject/main.cpp
g++ -Wl,-rpath,/home/f/Qt5.2.0/5.2.0/gcc_64 -Wl,-rpath,/home/f/Qt5.2.0/5.2.0/gcc_64/lib -o FirstQtProject main.o `pkg-config --cflags --libs opencv` -L/home/f/Qt5.2.0/5.2.0/gcc_64/lib -lQt5Core -lpthread
{ test -n "" && DESTDIR="" || DESTDIR=.; } && test $(gdb --version | sed -e 's,[^0-9][^0-9]*\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $DESTDIR" -ex quit 'FirstQtProject' && test -f FirstQtProject.gdb-index && objcopy --add-section '.gdb_index=FirstQtProject.gdb-index' --set-section-flags '.gdb_index=readonly' 'FirstQtProject' 'FirstQtProject' && rm -f FirstQtProject.gdb-index || true
20:45:16: The process "/usr/bin/make" exited normally.
20:45:16: Elapsed time: 00:01.
错误
在未选中“Run in terminal”的情况下运行项目
Starting /home/f/workspace/build-FirstQtProject-Desktop_Qt_5_2_0_GCC_64bit-Debug/FirstQtProject...
Demonstrate Canny edge detection
The program has unexpectedly finished.
/home/f/workspace/build-FirstQtProject-Desktop_Qt_5_2_0_GCC_64bit-Debug/FirstQtProject crashed
运行项目时未选中“Run in terminal”
http://i.stack.imgur.com/fAegn.jpg
调试
答案 0 :(得分:2)
在10.10之后的Ubuntu版本中,您将在更多相关的应用程序(例如QtCreator)中遇到此问题。它是Ubuntu的安全功能,可防止调试器附加到不属于他的进程。
这是以bug #3509 against QtCreator提交的。要解决此问题,请执行以下操作:
临时解决方案(在重启后无法生存):
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
在文件/etc/sysctl.d/10-ptrace.conf
(应该已存在)中,将kernel.yama.ptrace_scope
的值更改为0
,然后重新加载配置:sudo sysctl -p
。
我明确发布了临时解决方案,因为出于安全原因,您可能不希望在常规计算机上禁用此功能。