【问题标题】:a.at<uchar>(x,y) wont works in Vivado SDSoCa.at<uchar>(x,y) 在 Vivado SDSoC 中不起作用
【发布时间】:2020-01-08 06:37:33
【问题描述】:

我想从 Vivado SDSoC 中的 Mat 获取 2d 阵列,但我无法做到这一点,因为如 Xilinx(XAPP1167) 所述,

cv::Mat.at() 方法和 cvGet2D() 函数没有对应的等价物 综合库中的函数

感谢您的帮助。谢谢。

该项目是关于人脸识别系统的。系统首先会进行 viola-jone 人脸检测,然后将输出提供给 CNN 分类。 viola-jones 人脸检测的输出为 unsigned char*。 我将其转换回 Mat 并获得 2d 数组作为 CNN 分类器的输入。

#include <cstdio>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <ctime>
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <sys/mman.h>
#include <malloc.h>
#include <unistd.h>
#include <sds_lib.h>
#include <opencv2/core/core.hpp>
#include <opencv2/contrib/contrib.hpp>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/core/core_c.h"

using namespace cv;
using namespace std;
void resize_2_gray(unsigned char *imageIn, unsigned char *imageOut)
{
    int k=0;
    int coord;
    for (int i=0; i<240; i++) {
        for(int j=0; j<320; j++){
        //coord=(i*2*640+j*2)*3;
        #pragma HLS PIPELINE II=1
        coord=6*(i*640+j);
        imageOut[k] =  0.2126*imageIn[coord] + 0.7152*imageIn[coord+1] + 0.0722*imageIn[coord+2] ;
        k++;
        }
    }

}
int main(){
    Mat ROI;
    unsigned int cam_num =5;//camera USB port
    unsigned char *image_ROI;
    image_ROI = (unsigned char*)sds_alloc(sizeof(unsigned char)*56*46);
    VideoCapture stream(cam_num);
    stream.read(ROI);
    cvtColor(ROI,ROI, CV_BGR2RGB);
    resize_2_gray(ROI.data, image_ROI);

    double face_2darray [56][46]={0};
    int h1=3, w1=3,w2=46,h2=56;
    int x_ratio = (int)((w1<<16)/w2)+1;
    int y_ratio = (int)((h1<<16)/h2)+1;
    int x2,y2;
    //resize image before fed into classification
    for (int a=0;a<h2;a++)
    {
        for (int b=0;b<w2;b++)
        {
            x2=((b*x_ratio)>>16);
            y2=((a*y_ratio)>>16);
            image_ROI[(a*w2)+b]=ROI.data[(y2*w1)+x2];
            face_2darray[a][b]=(double)image_ROI[a+b];
            face_2darray[a][b]= 2*(face_2darray[a][b]/255)-1;
        }
    }
            Mat Image = Mat(56,46,0,image_ROI);
            imshow("Output",Image);

    sds_free(image_ROI);
}

【问题讨论】:

标签: vivado-hls


【解决方案1】:

我相信合成版本使用的是流式接口,所以你不能使用随机访问 API,而是必须一个一个地读取像素/元素。

【讨论】:

  • 你能帮我看看提供的代码吗?谢谢。
  • 通常在堆栈溢出中,人们会用最少的代码示例提出具体问题。您能否编辑代码以将您想要的示例与您的问题隔离开来?
  • 是的,上面提供的代码已经针对我的问题。 face_2darray 想从image_ROI获取值
  • @Yuheng1222 如果你想让别人看你的代码,你至少应该提供一个实际的minimal reproducible example。您的代码无法编译。存在语法错误和缺少声明。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多