我目前正在使用计算机视觉项目,问题在于一个函数采用模式(用于颜色)和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-&gt; SortRegions();在blobFind函数里面。 (segment-> readThresholds(“conf”);和segment-&gt; thresholdImage(data);过去也在函数内部,然后我将函数数据作为附加字段。 可能导致它的任何线索?当我在主循环中运行相同的序列(encoderuns,connectcomponents,extractregions,sortregions)时,它可以很好地工作。