0

我目前正在处理一个计算机视觉项目,问题在于一个将模式(颜色)和 SEGMENTATION 指针作为参数的函数。这是分段类 - http://pastebin.com/Z5D5pkqx 如果这段代码在我身上失败,这里是:

pair<cv::Point, cv::Point> blobFind(int mode, SEGMENTATION * segment){
SEGMENTATION segm(640, 480);
segment->EncodeRuns();
segment->ConnectComponents();
segment->ExtractRegions();
segment->SortRegions();
//cout << "& " << endl;
if(mode==1){
    //cout << "& " << endl;
int x1,x2,y1,y2;
if(segment->colors[ORANGE].list!=NULL){
    x1 = segment->colors[ORANGE].list->x1;
    y1 = segment->colors[ORANGE].list->y1;
    x2 = segment->colors[ORANGE].list->x2;
    y2 = segment->colors[ORANGE].list->y2;
    cout << y1 << endl;
    return make_pair(cv::Point(x1,x2), cv::Point(y1,y2));
    }

调用此函数的主要内容如下所示:

int main()
{
IMAGE_CONTEXT *ic;
XEvent event;
cv::Mat image;
cv::VideoCapture cap(0);
cap.set( CV_CAP_PROP_FRAME_WIDTH, 640 );
cap.set( CV_CAP_PROP_FRAME_HEIGHT, 480 );
height = 480;
width = 640;
pair<cv::Point, cv::Point> nxt;
SEGMENTATION segm( width, height );
SEGMENTATION * segment = &segm;
// Creating a new window
ic = new_window( "Video", 100, 100, width, height );
XImage *xImage1 = ic->xImage;
unsigned char *imageLine1 = (unsigned char*) xImage1 -> data;

while( !end ) {
    cap.read(image);
    data = image.data;
    segment->readThresholds("conf");
    segment->thresholdImage(data);
    nxt = blobFind(1, segment);

当代码到达这一点时发生分段错误:segment->SortRegions(); 在 blobFind 函数内部。(segment->readThresholds("conf"); 和 segment->thresholdImage(data); 也曾经在函数内部,然后我将函数数据作为附加字段提供。有什么线索可能导致它吗?当我在主循环中运行相同的序列(encoderuns、connectcomponents、extractregions、sortregions),它工作得很好。

4

0 回答 0