Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在opencv上将vec类型转换为标量类型_C++_Opencv_Vivado Hls - Fatal编程技术网

C++ 在opencv上将vec类型转换为标量类型

C++ 在opencv上将vec类型转换为标量类型,c++,opencv,vivado-hls,C++,Opencv,Vivado Hls,我正在研究一种用于检测标记的图像处理算法。这段代码使用opencv库,工作非常好。然而,我被要求使用HLS将其放入HDL以优化设计。问题是HLS不允许在标准代码中使用许多结构和表单。 我这里的主要问题是,我使用了一个定义为Vec3b的变量,它不能由HLS合成 我从opencv文档中读到: Vec : template class for short numerical vectors, a partial case of Matx template<typename _Tp, int n&

我正在研究一种用于检测标记的图像处理算法。这段代码使用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;
我还将整个代码放在这里,以防需要。我不是作者,所以它是用西班牙语写的

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;
        }
    }
}
void recorror(){

对于(int i=0;i )我既不理解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];
    }
#定义VALOR_pendente 10
#定义VALOR_PENDIENTE_TRUNCAR 10
int**h_依赖项;
int**原件;
h_pendentes=新整数*[480];
原始=新整数*[480];
对于(int i=0;i<480;++i)
{
h_pendientes[i]=新整数[640-1];
原[i]=新整数[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;
        }
    }

}
#包括
#包括
使用名称空间cv;
#定义勇猛10
#定义VALOR_PENDIENTE_TRUNCAR 10
int main()
{
Mat image=cv::imread(“Lenna.png”,cv\u LOAD\u image\u ANYCOLOR);
const int height=image.cols;
const int width=image.rows;
uchar*imageData=image.data;
int**h_依赖项;
int**原件;
h_pendentes=新整数*[480];
原始=新整数*[480];
对于(int i=0;i<480;++i)
{
h_pendientes[i]=新整数[640-1];
原[i]=新整数[640-1];
}
对于(int i=0;i<480;++i)
{
//colorAux=enHSB.at(0,i);//Cuidado con el acceso al revés
//int punto_frontial=(int)(colorAux[2]);
/*
*上面的代码段将每行的第一个像素分配给colorAux
*包括蓝色、绿色、红色。punto_将红色强度作为整数分配给像素
*简而言之,punto_Fronter是每行第0个像素的红色强度。
*/
int索引=0*width+i;
int punto_frontial=(int)imageData[3*索引+2];//访问像素的红色强度。
对于(int j=1;j<640-1;++j)
{
int indexReverse=i*width+j;
int亮度=(int)图像数据[3*索引+2];
h_pendientes[i][j]=亮度-前punto_;

如果(!(h_pendientes[i][j]>VALOR_PENDIENTE | h| h|pendientes[i][j]VALOR_PENDIENTE | u TRUNCAR | h| h pendientes[i][j]>h_pendientes[i][j][1]最后,我用标量表(或者更精确地说,是来自
hls\u video.h
的结构)替换了
Vec3b
类型。 然后,我使用
.val[]
访问此表中的数据


它似乎是工作的,即使在与软件通信时可能是个问题。

HDL和HLS是指什么?@ ZDAR HDL代表硬件描述语言,一种描述硬件IP的语言。HLS代表高级合成,它是一种用于将高级语言如C++翻译成HDL的方法。
#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;
        }
    }

}