OpenCV错误“断言失败” [英] OpenCV Error "Assertion Failed"
问题描述
我已经编写了一个类来管理图像并验证Mat图像上的像素值,在if和else的测试中。
这是我编写的代码的一部分,产生问题的具体过程:
bool cubo :: verifica_punti(Mat& I, double TC [ 4 ] [ 4 ], double fc [ 2 ], double KC [ 5 ], double cc [ 2 ], double alpha){
< span class =code-keyword> for ( int i = 0 ; i< 8; i ++){
// normalizzazione
double PN [ 2 ] = {V [i] .x / V [i] .z,V [I] .Y / V [I] .Z};
// calcolo delle componenti
double r2 = pow(PN [ 0 ], 2 。< span class =code-digit> 0 )+ pow(PN [ 1 ], 2 。 0 );
// distorsione tangenziale
double dx [ 2 ] = {((2 * KC [ 2 ] * PN [ 0 ] * PN [ 1 ])+(KC [ 3 ] *(r2 + 2 * pow(PN [ 0 ], 2 。< span class =code-digit> 0 )))),(KC [ 2 ] *(r2 + 2 * pow(PN [ 1 ], 2 。 0 ))+ 2 * KC [ 3 ] * PN [ 0 ] * PN [ 1 跨度>])};
// componenti sul piano
double xd [ 2 ] = {((1 + KC [ 0 ] * r2 + KC [ 1 ] * pow(r2, 2 。 0 )+ KC [ 4 ] * pow(r2, 3 。 0 ))* PN [ 0 ] + dx [ 0 ]),((1 + KC [ 0 ] * r2 + KC [ 1 ] * pow(r2 , 2 。 0 )+ KC [ 4 ] * pow(r2, 3 。 0 ))* PN [ 1 ] + dx [ 1 ])};
// 像素中的calcolo delle坐标
int xp = ceil(fc [ 0 ] *(xd [ 0 ] + alpha * xd [ 1 ])+ cc [ 0 ]);
int yp = ceil(fc [ 1 ] * xd [ 1 ] + cc [ 1 ]);
// cout<< endl<<XP =<< xp<<YP =<< yp<< endl;
// 每个测试的valore temporaneo
// uchar pix = 1;
if ((yp> 720 || yp< 0))
{
return false ;
}
else if ((xp> 1280 || xp< 0) ){
return false ;
}
else
{
Scalar pix = I.at< uchar>(yp,xp);
if (pix.val [ 0 ] == 0 )
{
return false ;
}
else
return 真跨度>;
}
}
};
这是我班级的一种方法CUBO。
程序运行时,我收到此错误并导致程序崩溃:
http://imageshack.com/i/10r512j [ ^ ]
有人可以帮我吗?
< blockquote> make for loop 8 to 4
Quote:bool cubo :: verifica_punti(Mat& I,double TC [4] [4],double fc [2],double KC [5],double cc [2],double alpha){
for(int i = 0; i< 4; i ++){
// normalizzazione
Hi,
I have write a class to manage images and to verify value of pixel on a Mat image, in a test with if and else.
This is a part of the code that I've write, the specific procedure that creates problems:
bool cubo::verifica_punti(Mat& I, double TC[4][4], double fc[2],double KC[5], double cc[2],double alpha){
for (int i=0;i<8;i++){
//normalizzazione
double PN[2] = { V[i].x/V[i].z, V[i].y/V[i].z};
//calcolo delle componenti
double r2 = pow(PN[0],2.0) + pow(PN[1],2.0);
//distorsione tangenziale
double dx[2]={((2*KC[2]*PN[0]*PN[1])+(KC[3]*(r2+2*pow(PN[0],2.0)))),(KC[2]*(r2+2*pow(PN[1],2.0))+2*KC[3]*PN[0]*PN[1])};
//componenti sul piano
double xd[2]={((1+KC[0]*r2+KC[1]*pow(r2,2.0)+KC[4]*pow(r2,3.0))*PN[0]+dx[0]),((1+KC[0]*r2+KC[1]*pow(r2,2.0)+KC[4]*pow(r2,3.0))*PN[1]+dx[1])};
//calcolo delle coordinate in pixel
int xp = ceil(fc[0]*(xd[0]+alpha*xd[1])+cc[0]);
int yp = ceil(fc[1]*xd[1]+cc[1]);
//cout<<endl<<"XP = "<<xp<<" YP = "<<yp<<endl;
//valore temporaneo per testare
//uchar pix = 1;
if ((yp>720||yp<0))
{
return false;
}
else if ((xp>1280||xp<0)){
return false;
}
else
{
Scalar pix = I.at<uchar>(yp,xp);
if (pix.val[0]==0)
{
return false;
}
else
return true;
}
}
};
This is a method of my class CUBO.
When program run, I receive this error and program crash:
http://imageshack.com/i/10r512j[^]
can someone help me??
make for loop 8 to 4
Quote:bool cubo::verifica_punti(Mat& I, double TC[4][4], double fc[2],double KC[5], double cc[2],double alpha){
for (int i=0;i<4;i++){
//normalizzazione
这篇关于OpenCV错误“断言失败”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!