很簡單的程序,只是使用了函數
定義部分
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();
}
QCoreApplication a(argc, argv);
這是main函數第一句,請解釋一下這個**a**是怎麼回事!解釋清楚了,你應該明白問題出在哪了!