Dandelion_fly
Dandelion_fly
采纳率100%
2015-05-08 02:04 阅读 8.6k

error: no match for 'operator[]'

很简单的程序,只是使用了函数
定义部分
int a[500],e[500];
然后下面所有尝试对a数组进行操作的全部报错
a[p]=0;
a[p]++;等
错误提示:
rror: no match for 'operator[]' (operand types are 'QCoreApplication' and 'int')
a[p]++;
^
而且奇怪的是相同的e数组却没有错误提示(或者将a数组改掉之后就会出现错误提示了吧)

这是主函数部分
#include
#include"opencv2/imgproc/imgproc.hpp"
#include"opencv2/highgui/highgui.hpp"
#include
#include
//#include
#include
#include
#include
#include
#include
#include

using namespace std;
using namespace cv;

Mat marker_mask;
Mat markers;
Mat img0,img,img1,img2,img_propo_measure,img_gray,wshed,roi_circle,roi_circle2,res,marker_circle,marker_circle2;
Point prev_pt(-1,-1),pt2(-1,-1),prev_pt2(-1,-1),pt1(-1,-1),prev_pt1(-1,-1),center_of_circle(-1,-1);
int a[500],e[500];
double d[500],f[500];
int b=1,pixels=1;
double bound_num=0,comp_count;
double c=0,radius,roi_w,roi_h;
vectorx;
vector > storage;
vector contours;

void img_propo_measure_fun(int event,int,int,int,void*);
void on_mouse(int event,int,int,int,void*);
void on_mouse2(int event,int,int,int,void*);
void sortation();
void convertion_workoutG();
void output();

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
if(argc==2&&(img0=imread(argv[1],1))!=0)
{

}
else
{
img0=imread("e:/codes/sample2.jpg");

}
string filemname="811.jpg";
RNG rng=RNG(-1);
namedWindow("image",1);
namedWindow("cut",1);
namedWindow("watershed transform",1);
namedWindow("proportion",1);

img=img0.clone();
img_propo_measure=img0.clone();

imshow("Proportion",img_propo_measure);
imshow("cut",img);
img1=img.clone();

setMouseCallback("Proportion",img_propo_measure_fun,0);
setMouseCallback("cut",on_mouse2,0);
setMouseCallback("image",on_mouse,0);
for(;;)
{
char c=waitKey();
if(c==27||c=='b')
break;
else if(c=='r')
{
//marker_mask=Mat::zeros();
img1.copyTo(img2);
imshow("image",img2);
}
else if(c=='w'||c==' ')
{
comp_count=1;
findContours(marker_mask,storage,&contours,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
//markers=Mat::zeros();
for(int i;i //contours declaration is changed, trouble may be called,the next contours should be write as?
{
Scalar color=Scalar(rng.uniform(0,255),rng.uniform(0,255),rng.uniform(0,255));
drawContours(markers,contours,i,color,1,8,vector(),0,Point());

    }
    Mat color_tab(1,comp_count,CV_8UC3);
    for(int i=0;i<comp_count;i++)
    {
        uchar* ptr=color_tab.ptr<uchar>(i*3);
        ptr[0]=(uchar)(RNG::next(&rng)%180+50);//重置并返回32u的随机值
        ptr[1]=(uchar)(RNG::next(&rng)%180+50);
        ptr[2]=(uchar)(RNG::next(&rng)%180+50);

    }

    double t=(double)getTickCount();
    watered(res,markers);
    t=(double)getTickCount()-t;

    marker_circle=Mat::zeros(markers.size(),CV_32S);
    marker_circle2=Mat::zeros(markers.size(),CV_32S);
    bitwise_and(markers,markers,marker_circle,roi_circle);
    bitwise_and(markers,markers,marker_circle,roi_circle);

    for(int p=0;p<500;p++)
    {
        a[p]=0;
        e[p]=0;
    }
    int k=0;
    bound_num=0;

    for(int i=0;i<marker_circle2.rows;i++)
        for(int j=0;i<marker_circle2.cols-1;j++)
        {
            int n=0;
            int pres=CV_MAT_ELEM(marker_circle2,int,i,j);
            int next=CV_MAT_ELEM(marker_circle2,int,i,j+1);
            int sub=abs(pres-next);
            if(pres*next==0&&sub!=0)
            {
                for(n=0;n<k+1;n++)
                    if(e[n]==sub)
                        break;
                if(n==k+1)
                {
                    e[k]=sub;
                    bound_num++;
                    k++;
                }
            }
        }
    for(int i=0;i<marker_circle.rows;i++)
        for(int j=0;j<marker_circle.cols;j++)
        {
            int idx=CV_MAT_ELEM(marker_circle,int,i,j);
            for(int p=1;p<comp_count;p++)
            {
                if((idx-1)==b++)
                {
                    for(int boundary=0;boundary<k+1;boundary++)
                    {
                        if(e[boundary]==(b+1))
                            a[p]++;
                    }
                    a[p]++;
                    break;
                }
            }
            b=1;
            uchar* dst=&CV_MAT_ELEM(whed,uchar,i,j*3);
            if(idx==-1)
                dst[0]=dst[1]=dst[2]=(uchar)255;
            else if(idx<=0||idx>comp_count)
                dst[0]=dst[1]=dst[2]=(uchar)0;
            else
            {
                uchar* ptr=color_tab.ptr<uchar>(idx-1)*3;
                dst[0]=ptr[0];
                dst[1]=ptr[1];
                dst[2]=ptr[2];
            }
        }
    addWeighted(wshed,0.5,img_gray,0.5,0,wshed);
    imshow("watershed transform",wshed);





}

}
for(int i=1;i<comp_count;i++)
{
for(int j=i;j<comp_count;j++)
{
if(a[i]<a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
convertion_workoutG();
sortation();
output();
waitKey(0);

return a.exec();
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • 已采纳
    u012898195 COCOCOBoy 2015-05-08 06:47

    QCoreApplication a(argc, argv);
    这是main函数第一句,请解释一下这个**a**是怎么回事!解释清楚了,你应该明白问题出在哪了!

    点赞 1 评论 复制链接分享
  • oyljerry oyljerry 2015-05-08 02:45

    怎么看也不是这里的问题,有没有更详细的信息

    点赞 评论 复制链接分享
  • Dandelion_fly Dandelion_fly 2015-05-08 04:53

    这是主函数部分
    #include
    #include"opencv2/imgproc/imgproc.hpp"
    #include"opencv2/highgui/highgui.hpp"
    #include
    #include
    //#include
    #include
    #include
    #include
    #include
    #include
    #include

    using namespace std;
    using namespace cv;

    Mat marker_mask;
    Mat markers;
    Mat img0,img,img1,img2,img_propo_measure,img_gray,wshed,roi_circle,roi_circle2,res,marker_circle,marker_circle2;
    Point prev_pt(-1,-1),pt2(-1,-1),prev_pt2(-1,-1),pt1(-1,-1),prev_pt1(-1,-1),center_of_circle(-1,-1);
    int a[500],e[500];
    double d[500],f[500];
    int b=1,pixels=1;
    double bound_num=0,comp_count;
    double c=0,radius,roi_w,roi_h;
    vectorx;
    vector > storage;
    vector contours;

    void img_propo_measure_fun(int event,int,int,int,void*);
    void on_mouse(int event,int,int,int,void*);
    void on_mouse2(int event,int,int,int,void*);
    void sortation();
    void convertion_workoutG();
    void output();

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    if(argc==2&&(img0=imread(argv[1],1))!=0)
    {

    }
    else
    {
        img0=imread("e:/codes/sample2.jpg");
    
    }
    string filemname="811.jpg";
    RNG rng=RNG(-1);
    namedWindow("image",1);
    namedWindow("cut",1);
    namedWindow("watershed transform",1);
    namedWindow("proportion",1);
    
    img=img0.clone();
    img_propo_measure=img0.clone();
    
    imshow("Proportion",img_propo_measure);
    imshow("cut",img);
    img1=img.clone();
    
    setMouseCallback("Proportion",img_propo_measure_fun,0);
    setMouseCallback("cut",on_mouse2,0);
    setMouseCallback("image",on_mouse,0);
    for(;;)
    {
        char c=waitKey();
        if(c==27||c=='b')
            break;
        else if(c=='r')
        {
            //marker_mask=Mat::zeros();
            img1.copyTo(img2);
            imshow("image",img2);
        }
        else if(c=='w'||c==' ')
        {
            comp_count=1;
            findContours(marker_mask,storage,&contours,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
            //markers=Mat::zeros();
            for(int i;i<contours.size();i++,comp_count++)
                //contours declaration is changed, trouble may be called,the next contours should be write as?
            {
                Scalar color=Scalar(rng.uniform(0,255),rng.uniform(0,255),rng.uniform(0,255));
                drawContours(markers,contours,i,color,1,8,vector<Vec4i>(),0,Point());
    
            }
            Mat color_tab(1,comp_count,CV_8UC3);
            for(int i=0;i<comp_count;i++)
            {
                uchar* ptr=color_tab.ptr<uchar>(i*3);
                ptr[0]=(uchar)(RNG::next(&rng)%180+50);//重置并返回32u的随机值
                ptr[1]=(uchar)(RNG::next(&rng)%180+50);
                ptr[2]=(uchar)(RNG::next(&rng)%180+50);
    
            }
    
            double t=(double)getTickCount();
            watered(res,markers);
            t=(double)getTickCount()-t;
    
            marker_circle=Mat::zeros(markers.size(),CV_32S);
            marker_circle2=Mat::zeros(markers.size(),CV_32S);
            bitwise_and(markers,markers,marker_circle,roi_circle);
            bitwise_and(markers,markers,marker_circle,roi_circle);
    
            for(int p=0;p<500;p++)
            {
                a[p]=0;
                e[p]=0;
            }
            int k=0;
            bound_num=0;
    
            for(int i=0;i<marker_circle2.rows;i++)
                for(int j=0;i<marker_circle2.cols-1;j++)
                {
                    int n=0;
                    int pres=CV_MAT_ELEM(marker_circle2,int,i,j);
                    int next=CV_MAT_ELEM(marker_circle2,int,i,j+1);
                    int sub=abs(pres-next);
                    if(pres*next==0&&sub!=0)
                    {
                        for(n=0;n<k+1;n++)
                            if(e[n]==sub)
                                break;
                        if(n==k+1)
                        {
                            e[k]=sub;
                            bound_num++;
                            k++;
                        }
                    }
                }
            for(int i=0;i<marker_circle.rows;i++)
                for(int j=0;j<marker_circle.cols;j++)
                {
                    int idx=CV_MAT_ELEM(marker_circle,int,i,j);
                    for(int p=1;p<comp_count;p++)
                    {
                        if((idx-1)==b++)
                        {
                            for(int boundary=0;boundary<k+1;boundary++)
                            {
                                if(e[boundary]==(b+1))
                                    a[p]++;
                            }
                            a[p]++;
                            break;
                        }
                    }
                    b=1;
                    uchar* dst=&CV_MAT_ELEM(whed,uchar,i,j*3);
                    if(idx==-1)
                        dst[0]=dst[1]=dst[2]=(uchar)255;
                    else if(idx<=0||idx>comp_count)
                        dst[0]=dst[1]=dst[2]=(uchar)0;
                    else
                    {
                        uchar* ptr=color_tab.ptr<uchar>(idx-1)*3;
                        dst[0]=ptr[0];
                        dst[1]=ptr[1];
                        dst[2]=ptr[2];
                    }
                }
            addWeighted(wshed,0.5,img_gray,0.5,0,wshed);
            imshow("watershed transform",wshed);
    
    
    
    
    
        }
    }
    for(int i=1;i<comp_count;i++)
    {
        for(int j=i;j<comp_count;j++)
        {
            if(a[i]<a[j])
            {
                int temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    convertion_workoutG();
    sortation();
    output();
    waitKey(0);
    
    
    return a.exec();
    

    }

    点赞 评论 复制链接分享
  • Dandelion_fly Dandelion_fly 2015-05-08 04:54

    还有其他错误,打算一点点改,不过应该不会其他部分的错误导致这个错误吧

    点赞 评论 复制链接分享

相关推荐