在 opencv 上将 vec 类型转换为标量类型
Convert a vec type into a scalar type on opencv
我正在研究一种图像处理算法来检测标记。该代码使用 opencv 库并且运行良好。但是我被要求使用 HLS 将其放入 HDL 中以优化设计。问题是 HLS 不允许使用标准代码中使用的许多结构和形式。
我这里的主要问题是我使用了一个定义为Vec3b
的变量,它不能被HLS合成。
我从 opencv 文档中读到这个:
Vec : template class for short numerical vectors, a partial case of Matx
template<typename _Tp, int n> class Vec : public Matx<_Tp, n, 1> {...};
typedef Vec<uchar, 3> Vec3b;
在不进入有关 HLS 的详细信息的情况下,我想知道是否可以将 Vec3b
类型替换为可以像 Scalar_
这样可合成的类型,或者将其作为简单的 Matx
。
关于标量,我在文档中找到了这个:
It is possible to convert Vec<T,2> to/from Point_, Vec<T,3> to/from Point3_ , and Vec<T,4> to CvScalar or Scalar_. Use operator[] to access the elements of Vec.
我也把整个代码放在这里以备不时之需。我不是作者,所以它是用西班牙语写的。
void recorroHorizontal(){
for(int i=0;i<480;i++){
colorAux=enHSB.at<Vec3b>(0,i); //Cuidado con el acceso al revés
int punto_anterior = (int)(colorAux[2]);
for(int j=1;j<640-1;j++){
colorAux=enHSB.at<Vec3b>(i,j); //al reves j e i
float brightness=colorAux[2];
int brightnessi=(int)(brightness);
h_pendientes[i][j]=brightnessi- punto_anterior;
if(!(h_pendientes[i][j]>VALOR_PENDIENTE || h_pendientes[i][j]<-VALOR_PENDIENTE)){
if(!(h_pendientes[i][j] + h_pendientes[i][j-1] >VALOR_PENDIENTE_TRUNCAR || h_pendientes[i][j] + h_pendientes[i][j+1]<-VALOR_PENDIENTE_TRUNCAR)){
h_pendientes[i][j]=0;
}
}
if(j<2 || i<2 || 640-1 ==i){h_pendientes[i][j]=0;}
punto_anterior=brightnessi;
original[i][j]=brightnessi;
}
}
}
最后,我将 Vec3b
类型替换为 table 标量(或 hls::Saclar 更准确地说,hls_video.h
中的结构)。
然后,我使用 .val[]
.
访问此 table 中的数据
它似乎可以工作,即使在与软件通信时可能会出现问题。
我正在研究一种图像处理算法来检测标记。该代码使用 opencv 库并且运行良好。但是我被要求使用 HLS 将其放入 HDL 中以优化设计。问题是 HLS 不允许使用标准代码中使用的许多结构和形式。
我这里的主要问题是我使用了一个定义为Vec3b
的变量,它不能被HLS合成。
我从 opencv 文档中读到这个:
Vec : template class for short numerical vectors, a partial case of Matx
template<typename _Tp, int n> class Vec : public Matx<_Tp, n, 1> {...};
typedef Vec<uchar, 3> Vec3b;
在不进入有关 HLS 的详细信息的情况下,我想知道是否可以将 Vec3b
类型替换为可以像 Scalar_
这样可合成的类型,或者将其作为简单的 Matx
。
关于标量,我在文档中找到了这个:
It is possible to convert Vec<T,2> to/from Point_, Vec<T,3> to/from Point3_ , and Vec<T,4> to CvScalar or Scalar_. Use operator[] to access the elements of Vec.
我也把整个代码放在这里以备不时之需。我不是作者,所以它是用西班牙语写的。
void recorroHorizontal(){
for(int i=0;i<480;i++){
colorAux=enHSB.at<Vec3b>(0,i); //Cuidado con el acceso al revés
int punto_anterior = (int)(colorAux[2]);
for(int j=1;j<640-1;j++){
colorAux=enHSB.at<Vec3b>(i,j); //al reves j e i
float brightness=colorAux[2];
int brightnessi=(int)(brightness);
h_pendientes[i][j]=brightnessi- punto_anterior;
if(!(h_pendientes[i][j]>VALOR_PENDIENTE || h_pendientes[i][j]<-VALOR_PENDIENTE)){
if(!(h_pendientes[i][j] + h_pendientes[i][j-1] >VALOR_PENDIENTE_TRUNCAR || h_pendientes[i][j] + h_pendientes[i][j+1]<-VALOR_PENDIENTE_TRUNCAR)){
h_pendientes[i][j]=0;
}
}
if(j<2 || i<2 || 640-1 ==i){h_pendientes[i][j]=0;}
punto_anterior=brightnessi;
original[i][j]=brightnessi;
}
}
}
最后,我将 Vec3b
类型替换为 table 标量(或 hls::Saclar 更准确地说,hls_video.h
中的结构)。
然后,我使用 .val[]
.
它似乎可以工作,即使在与软件通信时可能会出现问题。