jeudi 29 décembre 2016

How do I prevent OpenCV from executing __fastfail?

I wanted to try and learn OpenCV (currently using version 2.4.13), so I set up this small program to output an RGB filter from a camera stream. However when I run the program it only runs for about 10 frames, and OpenCV executes this segment of code from invalid_parameter.cpp from the windows SDK:

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

What is the reason this function is being executed and how do I prevent it from happening again?

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) {
    cvtColor(input, output, COLOR_BGR2RGB);
    inRange(output, 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);
}

Aucun commentaire:

Enregistrer un commentaire