在VS中运行没有问题,在linux中运行出错,即DivideEye()运行后,再执行JiFen(Mat &Leye_B),报错
部分代码如下
部分代码如下
void ImgProcess::DivideEye()
{
if (drawing_box.width>0)
{
CvRect leye_box;
/*leye_box.x = drawing_box.x + 1;
leye_box.y = drawing_box.y + 1;
leye_box.height = drawing_box.height - 1;
leye_box.width = floor(drawing_box.width / 2) - 1;*/
leye_box.x = drawing_box.x + 5;
leye_box.y = drawing_box.y + 1;
leye_box.height = drawing_box.height - 5;
leye_box.width = floor((drawing_box.width / 2) - 20);
CvRect reye_box;
/*reye_box.x = leye_box.x + leye_box.width;
reye_box.y = drawing_box.y + 1;
reye_box.height = drawing_box.height - 1;
reye_box.width = leye_box.width - 1;*/
reye_box.x = leye_box.x + leye_box.width+20;
reye_box.y = drawing_box.y + 1;
reye_box.height = drawing_box.height - 5;
reye_box.width = leye_box.width - 1;
Leye = inimg(leye_box);
Reye = inimg(reye_box);
// imshow("L",Leye);
// imshow("R",Reye);
}
}
float ImgProcess::JiFen(Mat &Leye_B){
int max1;
int max2;
IplImage *src;
src = &IplImage(Leye_B);
IplImage* paintx = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1);
IplImage* painty = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1);
cvZero(paintx);
cvZero(painty);
int* v = new int[src->width];
int* h = new int[src->height];
memset(v, 0, src->width * 4);
memset(h, 0, src->height * 4);
int x, y;
CvScalar s, t;
for (x = 0; x<src->width; x++)
{
for (y = 0; y<src->height; y++)
{
s = cvGet2D(src, y, x);
if (s.val[0] == 0)
v[x]++;
}
}
for (x = 0; x<src->width; x++)
{
for (y = 0; y<v[x]; y++)
{
t.val[0] = 255;
cvSet2D(paintx, y, x, t);
}
}
for (y = 0; y<src->height; y++)
{
for (x = 0; x<src->width; x++)
{
s = cvGet2D(src, y, x);
if (s.val[0] == 0)
h[y]++;
}
}
for (y = 0; y<src->height; y++)
{
for (x = 0; x<h[y]; x++)
{
t.val[0] = 255;
cvSet2D(painty, y, x, t);
}
}
max1 = v[0];
for (int x = 1; x<src->width; x++){
if (max1<v[x])
max1 = v[x];
}
int count1 = 0;
for (int x = 0; x<src->width; x++){
if (v[x] != 0)
count1++;
}
float rate1 = 0;
if (count1 != 0)
rate1 = max1*1.0 / count1;
max2 = h[0];
for (int x = 1; x<src->height; x++){
if (max2<h[x])
max2 = h[x];
}
int count2 = 0;
for (int x = 0; x<src->height; x++){
if (h[x] != 0)
count2++;
}
float rate2 = 0;
if (count2!=0)
rate2 = max2*1.0 / count2;
//cvNamedWindow("二值图像", 1);
//cvNamedWindow("垂直积分投影", 1);
cvNamedWindow("水平积分投影", 1);
//cvShowImage("二值图像", src);
//cvShowImage("垂直积分投影", paintx);
cvShowImage("水平积分投影", painty);
//printf("rate1:%f\n",rate1);
//printf("rate2:%f\n", rate2);
float rate = 0.5*rate1 + 0.5*rate2;
// printf("rate:%f\n", rate);
return rate;
/*cvWaitKey(0);
cvDestroyAllWindows();
cvReleaseImage(&src);
cvReleaseImage(&paintx);
cvReleaseImage(&painty);*/
}
解决方案
40
IplImage *src,csrc; csrc = IplImage(Leye_B); src=&csrc;