2016-12-29 3 views
-1

Ich wollte OpenCV versuchen (derzeit mit Version 2.4.13), also habe ich dieses kleine Programm eingerichtet, um einen RGB-Filter aus einem Kamerastrom auszugeben. Allerdings, wenn ich das Programm ausführen es läuft nur für etwa 10 Frames und OpenCV führt dieses Segment von Code aus invalid_parameter.cpp aus dem Windows SDK:Warum führt mein OpenCV-Programm die Windows __fastfail() -Methode aus?

if (IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE)) 
{ 
    __fastfail(FAST_FAIL_INVALID_ARG); 
} 

Der Code scheint zu stoppen, wenn die Pipeline :: findContour Funktion ausführen , aber wenn ich versuche, Breakpoints zu debuggen, werden sie nie getroffen, wenn sie innerhalb der Methode platziert werden, und das Durchlaufen funktioniert für diese bestimmte Methode nicht.

Aus welchem ​​Grund wird diese Fehlerfunktion ausgeführt und wie verhindere ich, dass sie erneut auftritt?

main.cpp:

#include <iostream> 
#include "Pipeline.h" 

int main() 
{ 
    Pipeline *pipeline = new Pipeline(); 

    VideoCapture feed; 
    Mat frame; 
    if (!feed.open(0)) 
     return -1; 

    //This for loop runs 7000 times for just for debug purposes 
    for (auto i = 0; i < 7000; i++) 
    { 
     feed >> frame; 
     if (frame.empty()) 
      break; 
     cv::waitKey(1); 
     pipeline->setsource0(frame); 
     try 
     { 
      pipeline->Process(); 
     } 
     catch (const std::exception& e) 
     { 
      cerr << e.what(); 
     } 
     Mat* image = pipeline->getrgbThresholdOutput(); 
     cv::imshow("Output", *image); 
    } 
    return 0; 
} 

pipeline.h:

#pragma once 
#include <opencv2/objdetect/objdetect.hpp> 
#include <opencv2/highgui/highgui.hpp> 
#include <opencv2/imgproc/imgproc.hpp> 
#include <opencv2/core/core.hpp> 
#include <opencv2/features2d.hpp> 
#include <iostream> 
#include <stdio.h> 
#include <stdlib.h> 
#include <map> 
#include <math.h> 
using namespace cv; 
using namespace std; 

class Pipeline { 
    private: 
     Mat source0; 
     Mat rgbThresholdOutput; 
     vector<vector<Point> > findContoursOutput; 
     void rgbThreshold(Mat &, double [], double [], double [], Mat &); 
     void findContours(Mat &, bool , vector<vector<Point> > &); 

    public: 
     Pipeline(); 
     void Process(); 
     void setsource0(Mat &source0); 
     Mat* getrgbThresholdOutput(); 
     vector<vector<Point> >* getfindContoursOutput(); 
}; 

pipeline.cpp:

#include "Pipeline.h" 

Pipeline::Pipeline() { 
} 

void Pipeline::Process(){ 
    //Step RGB_Threshold0: 
    //input 
    Mat rgbThresholdInput = source0; 
    double rgbThresholdRed[] = {100, 240}; 
    double rgbThresholdGreen[] = {40, 233.53535353535355}; 
    double rgbThresholdBlue[] = {50, 170}; 
    rgbThreshold(rgbThresholdInput, rgbThresholdRed, rgbThresholdGreen, rgbThresholdBlue, this->rgbThresholdOutput); 
    //Step Find_Contours0: 
    //input 
    Mat findContoursInput = rgbThresholdOutput; 
    bool findContoursExternalOnly = false; 
    findContours(findContoursInput, findContoursExternalOnly, this->findContoursOutput); 
} 

void Pipeline::setsource0(Mat &source0){ 
    source0.copyTo(this->source0); 
} 

void Pipeline::rgbThreshold(Mat &input, double red[], double green[], double blue[], Mat &output) { 
    inRange(input, Scalar(red[0], green[0], blue[0]), Scalar(red[1], green[1], blue[1]), output); 
} 

void Pipeline::findContours(Mat &input, bool externalOnly, vector<vector<Point> > &contours) { 
    contours.clear(); 
    int mode = externalOnly ? CV_RETR_EXTERNAL : CV_RETR_LIST; 
    int method = CHAIN_APPROX_SIMPLE; 
    cv::findContours(input, contours, mode, method); 
} 

Mat* Pipeline::getrgbThresholdOutput(){ 
    return &(this->rgbThresholdOutput); 
} 

vector<vector<Point> >* Pipeline::getfindContoursOutput(){ 
    return &(this->findContoursOutput); 
} 

Antwort

0

habe ich einige m order debugging und stellte fest, dass ich durch das Hinzufügen einer try and catch-Anweisung vor der findContours() -Methode dann erfolgreich durchgehen konnte. Dadurch konnte ich feststellen, dass das Konturenobjekt an zufälligen Punkten im Code NULL wurde, was die Funktionsweise der clear() -Methode verhinderte. Ich habe es dann in contours.empty() geändert, und der Code hat dann erfolgreich funktioniert.

+0

Was meinen Sie mit "das Konturenobjekt wurde NULL"? Nur Zeiger können NULL werden. Außerdem hat das Aufrufen von 'contures.empty()' (und das Ignorieren der Ausgabe) keine Auswirkung und wird wahrscheinlich vom Compiler optimiert. – chtz

Verwandte Themen