C++ OpenCV错误:cvInRangeS中的断言失败(src1.size==dst.size&;dst.type()==CV_8U)

C++ OpenCV错误:cvInRangeS中的断言失败(src1.size==dst.size&;dst.type()==CV_8U),c++,macos,opencv,C++,Macos,Opencv,大家好,我的社区!我使用的是MacBookPro OS X 10.8.5。我从源代码下载了一个构建的opencv,并用一个简单的示例对其进行了测试。它似乎工作得很好。我尽量不使用IDE。相反,我只是在文本编辑器中编写代码,然后从终端进行编译。我用 g++Follow_Ball.cpp-o Follow_Ballpkg配置--cflags--libs opencv 当我这样做时,我没有收到任何错误,但当我尝试运行可执行文件时。“/Follow\u Ball” 它给了我以下的错误 OpenCV错误:

大家好,我的社区!我使用的是MacBookPro OS X 10.8.5。我从源代码下载了一个构建的opencv,并用一个简单的示例对其进行了测试。它似乎工作得很好。我尽量不使用IDE。相反,我只是在文本编辑器中编写代码,然后从终端进行编译。我用 g++Follow_Ball.cpp-o Follow_Ball
pkg配置--cflags--libs opencv
当我这样做时,我没有收到任何错误,但当我尝试运行可执行文件时。“/Follow\u Ball” 它给了我以下的错误

OpenCV错误:cvInRangeS文件/opt/local/var/macports/build/_opt\u mports\u dports\u graphics\u OpenCV/OpenCV/work/OpenCV-2.4.7/modules/core/src/arithm.cpp第2972行中的断言失败(src1.size==dst.size&&dst.type() libc++abi.dylib:terminate调用引发异常 中止陷阱:6

其他信息可能相关的信息。。。 我正在尝试使用MacBook Pro内置的网络摄像头 我设置了“CvSize size640x480=CvSize(640480)”;我不确定这是否是我电脑的像素。也许这就是问题的根源?我还注释掉了第117行,因为我无法让它工作,我不认为我需要它,因为我只在球周围画了一条红线。我有点困惑,我应该如何调试这个

有人能帮我吗?我是opencv的新手,对如何调试它没有太多的知识或经验。 谢谢你们

(“顺便说一句,我正在学习教程”) 这是代码

#include <opencv/cvaux.h>
#include <opencv/highgui.h>
#include <opencv/cxcore.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>


int main(int argc, char* argv[]){

   // Default capture size - 640x480
    CvSize size640x480 = cvSize(640,480);
    // Open capture device. 0 is /dev/video0, 1 is /dev/video1, etc.
    // Web cam video stream is assinged to this 
    CvCapture *p_capWebCam; 
    //pointer to an image structure.
    //this will be the imput image from webcam
    IplImage *p_imgOriginal; 
    //Pointer to an immage structure 
    //this will be the processed black and white immage 
                            /* Ipl is short for Intel Immage processing library. This is the standard 
                                structure in opencv to work with immages. */
    IplImage *p_imgProcessed; 
    //Necessary storage variable to pass into cvHoughCircles()
    CvMemStorage *p_strStorage; 
    //pointer to an opencv sequence, will be returned by cvHough Circles() and will contain all circles 
    // calling cvGetSeqElem(p_seqCircles, i) willreturn 3 element array of i'th circle (see next variable)
    CvSeq *p_seqCircles;
    //pointer to a 3 element of array of floats
    //[0] => x position of detected object
    //[1] => y position of detected object
    //[2] => Radius of detected object
    float *p_fltXYRadius;         //pointer to a 3 element array of floats 

    int i;                      //loop counter
    char charCheckForEscKey;    //get char to escape

    p_capWebCam = cvCaptureFromCAM(0);  //If you have multiple webcams you might not want to use 0
                                        //However, since i have only one i pass the parameter 0 

    //check if the webcam works 
    if( p_capWebCam == NULL ){
         printf("ERROR: capture is NULL");  //If web cam wasnt plugged in for example we'd exit the program 
         getchar();                         //pause so that user sees the message 
         return(-1);                        //exit the program  
    }

    //declare the two windows 
    cvNamedWindow("Original", CV_WINDOW_AUTOSIZE );     // Origina image from webcam 
    cvNamedWindow("Processed", CV_WINDOW_AUTOSIZE);     // Processed image we will use for detecting circles 

    p_imgProcessed = cvCreateImage(size640x480,         //creates the immage for the Processed window
                                    IPL_DEPTH_8U, 1);   //8U is short for 8 bits unsigned  //we use 1 for greyscale if collow we use 3
                                                        //this is a greyscale immage so each pixel can go from 0->255 greyscale 
                                                        //it this was color "Red Green Blue" would be a value for each color: well call this 
                                                        //the depth 

    // Infinate while loop where fram is grabbed from cam and processed 
    while(1){           //for each frame... 

        p_imgOriginal = cvQueryFrame(p_capWebCam);  //get frame from webcam 
        //check to see if the frame capture was sucessfull 
        if(p_imgOriginal == NULL){      //if frame was not capture sucessfully
            printf("ERROR: frame is NULL \n" );
            getchar(); 
            break; 
        } 
        // 44:46 http://www.youtube.com/watch?v=2i2bt-YSlYQ&list=PLbqNFa0YhiNBHuQOwalaP5jNGExrmsGOO
         cvInRangeS(p_imgOriginal,                  //function input        //color
                        CV_RGB(175, 0 , 0),         //this is a macro, we want to capture a red ball at atleast 175 inclusive
                        CV_RGB(255, 100, 100),      //we allow a bit of green and blue: Redis max 256 not inclusive 
                        p_imgProcessed );            //function output       //black and white

         //alocate storage variable 
         p_strStorage   = cvCreateMemStorage(0);    //alocate necessary storage variable to pass int cvHoughCirlces()

         //now we apply agousian smoothing to the processed image. this will make it easyer for next func to pic circles
         cvSmooth(p_imgProcessed,                   //function input 
                    p_imgProcessed,                 //function output 
                    CV_GAUSSIAN,                    //Use Gaussian filter (averages nearby pixels, with closses having more wheight)
                    9,                              //Smothing filter window width 
                    9);                             //Smoothing filter window height  
                                                    //imigin a 9x9 box in the input immage it does stuff smooths out the output

        //fills a sequential structure with all circles in a processed immgage
        p_seqCircles = cvHoughCircles( p_imgProcessed,              //input: hast to be greyscale "no color"
                                        p_strStorage,               //Needs this we need not know why. passing this makes func ret pointer
                                        CV_HOUGH_GRADIENT ,         //Only option for this, two pass algorithim for detecting circles
                                        2,                          // size of this image/ (this value) = accumulator immage 
                                        p_imgProcessed->height/4,   //min distance in pixels between centers of detected circles 
                                        100,                //high threshold of Cany edge detector, called by cvHoughCircles 
                                        50,                 //low threshold of Cany edge detector, called by cvHoughCircles 
                                        10,                 //Minimub circle radius 
                                        400);               //max circle radius 

        for(i = 0; i < p_seqCircles->total; i++){           //for each element in sequential circles structure( i.e. for each object detected)

            p_fltXYRadius = (float*)cvGetSeqElem(p_seqCircles, i); //from the sequential struct, read the i'th value into a pointer to a float 
            printf("ball position x = %f, y = %f, r = %f \n", p_fltXYRadius[0],     //x position at center of circle 
                                                              p_fltXYRadius[1],     //y position at center of circle 
                                                              p_fltXYRadius[2]);    //radius of circle 

            //draw a small green circle at center of detected object
            cvCircle(p_imgOriginal,             //draw on the original image
                cvPoint(cvRound(p_fltXYRadius[0]),  cvRound(p_fltXYRadius[1])),     // center point of circle 
                                                3,                                  //3 pixel radius of circle 
                                                CV_RGB(0, 255, 0),                  //draw pure green
                                                CV_FILLED);                         //thickness, fill in the circle 
/*  this draws a circle around second ball but i dont need it 
            //draw a red circle around a detected object 
            cvCircle(p_imgOriginal,                                                 //draw on the original image
                cvPoint(cvRound(p_fltXYRadius[0]),  cvRound(p_fltXYRadius[1])),     // center point of circle 
                cvRound(p_fltXYRadius[2],                                           //radius of the circle in pixels
                CV_RGB(255, 0, 0),                                                  //draw pure red
                3);                                                           //thickness of circle in pixels 
*/


        }// end of for loop

        //now we just need to show the images that we already generated 
        cvShowImage("Original", p_imgOriginal);                         //original circle with detectec ball overlay
        cvShowImage("Processed", p_imgProcessed);                       //image after processing 

        cvReleaseMemStorage(&p_strStorage);                             //release what we alocated earlyer 
        charCheckForEscKey = cvWaitKey(10);                             //delay in ms, and get key press, if any
        if( charCheckForEscKey == 27) break;                            // if ascii 27 was pressed jump out of while loop


    }// end of while 

    cvReleaseCapture(&p_capWebCam); 
    cvDestroyWindow("Original"); 
    cvDestroyWindow("Processed"); 

    return(0); 

   }// end of program 
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
int main(int argc,char*argv[]){
//默认捕获大小-640x480
CvSize size640x480=CvSize(640480);
//打开捕获设备。0是/dev/video0,1是/dev/video1,等等。
//网络摄像机视频流被分配到这个位置
CvCapture*p_Cap网络摄像头;
//指向图像结构的指针。
//这将是网络摄像头输入的图像
IplImage*p_imgOriginal;
//指向image结构的指针
//这将是经过处理的黑白图像
/*Ipl是英特尔IMAGE处理库的缩写。这是标准
在opencv中使用immages的结构*/
IplImage*p_img已处理;
//传递到cvHoughCircles()中所需的存储变量
CVMEM存储*p_存储;
//指向opencv序列的指针,将由cvHough Circles()返回,并将包含所有圆
//调用cvGetSeqElem(p_seqCircles,i)将返回第i个圆的3个元素数组(参见下一个变量)
CvSeq*p_seq圆;
//指向浮点数组的3个元素的指针
//[0]=>检测到的对象的x位置
//[1] =>检测到的对象的y位置
//[2] =>检测对象的半径
float*p_fltxydradius;//指向3个元素的浮点数组的指针
int i;//循环计数器
char CHARCHECKFRESCKEY;//获取要转义的char
p_capWebCam=cvCaptureFromCAM(0);//如果您有多个网络摄像头,您可能不想使用0
//但是,由于我只有一个参数,所以我传递了参数0
//检查网络摄像头是否工作正常
如果(p_capWebCam==NULL){
printf(“ERROR:capture is NULL”);//例如,如果未插入网络摄像头,我们将退出该程序
getchar();//暂停以便用户看到消息
return(-1);//退出程序
}
//声明这两个窗口
cvNamedWindow(“原始”,CV_WINDOW_AUTOSIZE);//来自网络摄像头的原始图像
cvNamedWindow(“已处理”,CV_WINDOW_AUTOSIZE);//我们将用于检测圆的已处理图像
p_imgProcessed=cvCreateImage(size640x480,//为已处理的窗口创建IMAGE
IPL_DEPTH_8U,1);//8U是8位无符号的缩写//如果collow使用3,我们使用1表示灰度
//这是灰度图像,因此每个像素可以从0->255灰度
//这是颜色“红-绿-蓝”将是每种颜色的值:我们称之为
//深度
//将fram从cam中抓取并处理的内联while循环
而(1){//对于每一帧。。。
p_imgOriginal=cvQueryFrame(p_capWebCam);//从网络摄像机获取帧
//检查帧捕获是否成功
if(p_imgOriginal==NULL){//if帧未成功捕获
printf(“错误:帧为空\n”);
getchar();
打破
} 
// 44:46 http://www.youtube.com/watch?v=2i2bt-YSlYQ&list=PLbqNFa0YhiNBHuQOwalaP5jNGExrmsGOO
cvInRangeS(p_imgOriginal,//函数输入//颜色
CV_RGB(175,0,0),//这是一个宏,我们想在至少175(含175)处捕获一个红球
CV_RGB(255100100),//我们允许一点绿色和蓝色:Redis max 256不包括在内
p_imgProcessed);//函数输出//黑白
//alocate存储变量
p_strStorage=cvCreateMemStorage(0);//指定传递int-cvhoughcirles()所需的存储变量
//现在我们对处理后的图像应用高斯平滑。这将使下一个函数到pic圆更容易
cvSmooth(p_imgProcessed,//函数输入
p_imgProcessed,//函数输出
CV_GAUSSIAN,//使用GAUSSIAN过滤器(平均附近的像素,Closs的亮度更高)
9,//烟雾过滤器窗口宽度
9);
CvCapture * camera = cvCreateCameraCapture (CV_CAP_ANY);
IplImage *  current_frame = cvQueryFrame (camera);
CvSize size640x480 = cvSize(current_frame->width, current_frame->height); //tried 640, 480 : 600,500 : 500,600