中止陷阱:findchessboard有6个问题 [英] Abort trap:6 problem with findchessboard

查看:114
本文介绍了中止陷阱:findchessboard有6个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这个论坛的新人。我想问你一个一直困扰着我的问题。问题是我在互联网上找不到任何关于它的东西。在大学,我们必须这样做:编写一个程序: - 加载棋盘图像。 (这些想象在教授提供的文件夹中,它们代表华为智能手机棋盘拍摄的一些照片(15)。 - 检测每个图像中的棋盘交叉点。你需要的OpenCV函数是cv :: findChessboardCorners()(可选:考虑使用cv :: cornerSubPix()函数来细化角点检测)。



I用Maccode上的opencv 3.4.5用Xcode(c ++)编写它。



问题是在findChessboardCorners指令下它给我一个错误。我真的不明白是什么原因造成的,问题是中止陷阱:6。有人能帮帮我吗?



非常感谢你。



我的尝试:



I'm new on this forum. I'd like to ask you a question that has been annoying me all this day. the problem is that i don't find anything on internet about it. At the university we have to do this: Write a program that: -Loads the checkerboard images. ( these imagines are in a folder provided by the professor, they represent some pictures (15) taken by a Huawei smartphone of a chessboard). -Detects the checkerboard intersections in each image. The OpenCV function you need is cv::findChessboardCorners() (optional: consider to use the cv::cornerSubPix() function to refine the corner detections).

I'm writing it with Xcode ( c++) with opencv 3.4.5 on a Macbook.

The problem is that at the instruction "findChessboardCorners" it gets me an error. I really don't understand what causes it, the problem is " abort trap: 6. Can Someone help me?

Thank you very much.

What I have tried:

#include <sstream>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>


#define points_per_row 12
#define points_per_colum 8
using namespace cv;
using namespace std;


int main(int argc, const char * argv[]) {
    //read the file
    stringstream sst;
    vector<Mat> imagesArray;
    vector<Point2f> centers; //this will be filled by the detected centers
    Size patternSize = Size(11, 7); //2nd parameter FindchessCorners
    bool patternfound = false; //result of findChessboardCorners

    cout << "flag1 "<< endl;
    for(int i = 1; i < 16; i++){
        sst << "img" << i << ".jpg";
        cout << sst.str() << endl;
        imagesArray.push_back(imread(sst.str())); // putting into an array
        cout << "flag2" << endl;
    }//for
    //PUNTO 2: individuation of the corners of every image
    for(int i = 0 ; i <=15 ; i++){
        cout << "flag3" << endl;
        patternfound = findChessboardCorners(imagesArray[i] , patternSize , centers);
        if(patternfound){
            cout << "pattern found:"<< patternSize << endl;
            cout << "centroids: " << centers << endl;
            cout << "centroids array size: " << centers.size() << endl;
        for(int j = 0; j < centers.size(); j++)
                cout << centers[j] << endl;
        }
    }//for

return 0;
}

推荐答案

问题出在for循环中。你说有十五张图片。由于数组索引从零开始,因此第十五个图像将是索引十四,但是你的for循环输出到十五。更好的方法是定义一个常量:
The problem is in the for loops. You stated there are fifteen images. Since array indexes start with zero, the fifteenth image will be index fourteen but your for loop goes out to fifteen. A better way to do this would be to define a constant :
const int ImageCount = 15;

// and write the for loops like this :

for( int i = 0; i < ImageCount; ++i )
{
    sst << "img" << i + 1 << ".jpg";   // first image is 1

    // rest of code goes here
}

for( int i = 0 ; i < ImageCount ; i++)
{
    patternfound = findChessboardCorners( imagesArray[i] , patternSize , centers );

    // rest of code goes here
}

这应该更适合你


嗨。首先,谢谢你的回答。我遵循了你的宝贵建议(稍加修改,但这就是重点),但问题并没有改变。这段代码正确:



Hi. First of all, thank you for answering. I followed your valuable advice(with a little modification, but that's the point), but the problem doesn't change. here the piece of the code correct:

for(int i = 0 ; i < imagesArray.size(); i++){
                        cout << "flag3" << endl;
                        patternfound = findChessboardCorners(imagesArray[i] , patternSize , centers);
                        if(patternfound){
                            cout << "pattern found:"<< patternSize << endl;
                            cout << "centroids: " << centers << endl;
                            cout << "centroids array size: " << centers.size() << endl;
                        for(int j = 0; j < centers.size(); j++)
                                cout << centers[j] << endl;
                        }//if
                    }//for





但是编译时我仍然遇到同样的错误:





But still I get the same error when I compile:

libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.5) /tmp/opencv@3-20190117-71360-ynjwgu/opencv-3.4.5/modules/core/src/matrix.cpp:757: error: (-215:Assertion failed) dims <= 2 && step[0] > 0 in function 'locateROI'

Abort trap: 6


这篇关于中止陷阱:findchessboard有6个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆