我试图简单地找到轮廓并绘制。但是当代码到达findContours()
时代码崩溃了。我从inRange
Canny
convertTo
传递了一个框架,但还没有希望
有什么建议吗?
这是代码:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Mat HSVFrame, cfilterFrame, edgeFrame, Frame ;
vector<vector<Point>> cnts;
vector<Vec4i> hichy;
VideoCapture cap(0);
namedWindow("w", 1);
while(true){
cap >> Frame;
if(Frame.empty()){
break;
}
cv::cvtColor(Frame,HSVFrame,CV_BGR2HSV);
cv::inRange(HSVFrame , Scalar(0,155,60), Scalar(10,255,255), cfilterFrame);
cv::Canny(cfilterFrame , edgeFrame, 50,150 , 3);
// cfilterFrame.convertTo(edgeFrame, CV_8U ); //also tried this
cv::findContours(edgeFrame, cnts, hichy, CV_RETR_LIST,CV_CHAIN_APPROX_NONE);
for(int i =0 ; i < cnts.size() ; i++){
drawContours(Frame,cnts,i,Scalar(0,0,255),2, 8, hichy,0,Point(0,0));
}
imshow("w", Frame);
waitKey(30);
}
return a.exec();
}
的.pro:
QT += core
QT -= gui
TARGET = sevventhTry
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C://opencv//build//include
CONFIG(debug,debug|release){
LIBS += -LC://opencv//build//x86//vc12//lib\
-lopencv_world300\
-lopencv_world300d\
-lopencv_ts300d \
-lopencv_ts300
}
Qt creator 3.5.1 Qt 5.5.1 MSVC2013 openCV 3.0 赢8 x64