a.at< uchar>(x,y)在Vivado SDSoC中不起作用 [英] a.at<uchar>(x,y) wont works in Vivado SDSoC

查看:110
本文介绍了a.at< uchar>(x,y)在Vivado SDSoC中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

cv :: Mat<>.at()方法和cvGet2D()函数没有相应的等效项 可综合库中的功能

感谢您的帮助.谢谢.

该项目是关于人脸识别系统的.该系统首先将进行中提琴面部检测,然后将输出提供给CNN分类. 中提琴琼斯脸部检测的输出以无符号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);
}

解决方案

我认为综合版本正在使用流式接口,因此您不能使用随机访问API,而必须逐个读取像素/元素./p>

I want to get 2d array from a Mat in Vivado SDSoC but Im not able to do that because as described Xilinx(XAPP1167),

cv::Mat<>.at() method and cvGet2D() function have no corresponding equivalent function in the synthesizable library

I appreciate any help. Thank you.

The project is about face recognition system. The system first will go viola-jone face detection and then feed the output to the CNN classification. The output of viola-jones face detection is in unsigned char*. I plant to convert it back to Mat and obtain 2d array for the input of CNN Classifier.

#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);
}

解决方案

I believe the synthesized version is using a streaming interface, so you can't use random access APIs, and instead must read pixels/elements one by one.

这篇关于a.at&lt; uchar&gt;(x,y)在Vivado SDSoC中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆