我正在研究一种图像处理算法来检测标记。代码使用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_
那样合成的类型,或者将其作为简单的{{1}取回}}。
关于标量,我在文档中找到了这个:
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.
答案 0 :(得分:0)
我既不了解HLS,也不了解C ++ /西班牙语中的代码想要做什么。如果HLS解释了C ++代码,那么它很难理解在代码之外定义的结构或类型,例如在引用的库中。
我逐行翻译了你的代码。我只是改变了访问图像中每个像素的强度值的方式。
为了使某些工作成功,我定义了一些你应该澄清的变量,如:
#define VALOR_PENDIENTE 10
#define VALOR_PENDIENTE_TRUNCAR 10
int** h_pendientes;
int** original;
h_pendientes = new int*[480];
original = new int*[480];
for (int i = 0; i < 480; ++i)
{
h_pendientes[i] = new int[640 - 1];
original[i] = new int[640 - 1];
}
如果你进一步告诉我你的目的,那些价值观是什么我将非常乐意帮助你。
#include<opencv2/highgui.hpp>
#include<opencv2/core.hpp>
using namespace cv;
#define VALOR_PENDIENTE 10
#define VALOR_PENDIENTE_TRUNCAR 10
int main()
{
Mat image = cv::imread("Lenna.png", CV_LOAD_IMAGE_ANYCOLOR);
const int height = image.cols;
const int width = image.rows;
uchar * imageData = image.data;
int** h_pendientes;
int** original;
h_pendientes = new int*[480];
original = new int*[480];
for (int i = 0; i < 480; ++i)
{
h_pendientes[i] = new int[640 - 1];
original[i] = new int[640 - 1];
}
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]);
/*
* The code piece above assigns first pixel in each row to colorAux. It is a struct which
* includes blue,green,red. punto_anterior is assigned to pixels red intensity as integer
* In short, punto_anterior is red intensity of 0th pixel in each row.
*/
int index = 0 * width + i;
int punto_anterior = (int)imageData[3 * index + 2]; // access red intensity of pixel.
for (int j = 1; j < 640 - 1; ++j)
{
int indexReverse = i*width + j;
int brightness = (int)imageData[3 * index + 2];
h_pendientes[i][j] = brightness - 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 = brightness;
original[i][j] = brightness;
}
}
}
答案 1 :(得分:0)
最后,我将Vec3b
类型替换为Scalar表(或者hls :: Saclar更精确,来自hls_video.h
的结构)。
然后,我使用.val[]
访问此表中的数据。
它似乎有效,即使在与软件通信时可能会出现问题。