cvSetImageROI函数可能出的问题

//SetImageROI函数用起来可能有问题。当把一个区域定义为ROI后,如果在另一个函数中直接把这个ROI当做图片来处理而不加以特别对待会出问题。
int GetGLCM(const IplImage * img,double * result)
{
 if(NULL == img || NULL == result)
  return 1;
 int width = img->width;
 int height = img->height;
 if(img->roi!=NULL)
 {
  cout<<"ROI!!!!!!!!!!!!!!!"<<endl;
  width = img->roi->width;
  height = img->roi->height;
 }
 
 int * mark = new int[width * height]; //保存灰度级
 if(NULL == mark)
  return 2;
 int step = img->widthStep/sizeof(uchar);
 uchar * data = (uchar *)img->imageData;
 //划分灰度级
 if(img->roi!=NULL)
 {
  cout<<"ROI!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
  for (int i = 0;i < img->roi->height;++i)
  {
   for (int j = 0;j < img->roi->width;++j)
   {
    mark[i * width + j] = int(GLCM_CLASS * (data[(i + img->roi->yOffset) * img->width + j+img->roi->xOffset]) * 1.0 /256);
   }
  }
 }
 else
 {
  for (int i = 0;i < height;++i)
  {
   for (int j = 0;j < width;++j)
   {
    mark[i * width + j] = int(GLCM_CLASS * (data[i * width + j]) * 1.0 /256);
   }
  }
 }
 
 //计算四个方向的灰度共生矩阵,获取纹理特征
 //固定距离d = 1
 if(GetGLCMForOneDisOneTheta(mark,height,width,1,0,result) > 0)
 {
  for(int i = 0;i < 4;i++)
   result[i] = 0;
  cout<<"dayu 0"<<endl;
 }
 if(GetGLCMForOneDisOneTheta(mark,height,width,0,1,&result[4]) > 0)
 {
  for(int i = 0;i < 4;i++)
   result[4 + i] = 0;
  cout<<"dayu 0"<<endl;
 }
 if(GetGLCMForOneDisOneTheta(mark,height,width,1,1,&result[8]) > 0)
 {
  for(int i = 0;i < 4;i++)
   result[8 + i] = 0;
  cout<<"dayu 0"<<endl;
 }
 if(GetGLCMForOneDisOneTheta(mark,height,width,-1,1,&result[12]) > 0)
 {
  for(int i = 0;i < 4;i++)
   result[12 + i] = 0;
  cout<<"dayu 0"<<endl;
 }
 delete[] mark;
 return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值