Demo entry 6685583

c++

   

Submitted by anonymous on Dec 20, 2017 at 10:21
Language: C++. Code size: 2.6 kB.

void SGM(AXI_STREAM_IN &firstImage, AXI_STREAM_IN &secondImage, AXI_STREAM_OUT& DispMap, int rows, int cols)
{
	#pragma HLS RESOURCE variable=firstImage core=AXI4Stream metadata="-bus_bundle INPUT_STREAM"
	#pragma HLS RESOURCE variable=secondImage core=AXI4Stream metadata="-bus_bundle INPUT_STREAM"
	#pragma HLS RESOURCE variable=DispMap core=AXI4Stream metadata="-bus_bundle OUTPUT_STREAM"
	#pragma HLS INTERFACE ap_none port=cols
	#pragma HLS INTERFACE ap_none port=rows

	#pragma HLS interface ap_ctrl_none port=return

    unsigned short ***C;  // pixel cost array W x H x D
    unsigned short ***S;  // aggregated cost array W x H x D
    unsigned short ****A; // single path cost array 2 x W x H x D

        // allocate cost arrays
        C = new unsigned short**[rows];
        S = new unsigned short**[rows];

    	for (int row = 0; row < rows; ++row)
    	{
            C[row] = new unsigned short*[cols];
            S[row] = new unsigned short*[cols]();

            for (int col = 0; col < cols; ++col)
    		{
                C[row][col] = new unsigned short[DisparityRange];
                S[row][col] = new unsigned short[DisparityRange](); // initialize to 0
            }
        }

    	// #define PATHS_PER_SCAN 4
        A = new unsigned short ***[PATHS_PER_SCAN];
        for(int path = 0; path < PATHS_PER_SCAN; ++path)
    	{
            A[path] = new unsigned short **[rows];
            for (int row = 0; row < rows; ++row)
    		{
                A[path][row] = new unsigned short*[cols];
                for (int col = 0; col < cols; ++col)
    			{
                    A[path][row][col] = new unsigned short[DisparityRange];
                    for (unsigned int d = 0; d < DisparityRange; ++d)
    				{
                        A[path][row][col][d] = 0;
                    }
                }
            }
        }
	#pragma HLS DATAFLOW // must use data flow to stream the data

	cv::Mat leftimage(rows, cols, CV_8UC1);
	cv::Mat rightimage(rows, cols, CV_8UC1);
	AXIvideo2cvMat(firstImage, leftimage);
	AXIvideo2cvMat(secondImage, rightimage);

	/* 计算每个像素的 cost 值 */
	calculatePixelCost(leftimage, rightimage, DisparityRange, C);
	/* 开始代价聚合 */
	aggregateCosts(leftimage.rows, leftimage.cols, DisparityRange, C, A, S);

	cv::Mat disparityMap = cv::Mat(cv::Size(leftimage.cols, leftimage.rows), CV_8UC1, cv::Scalar::all(0));
	/* 计算视差 */
	computeDisparity(S, leftimage.rows, leftimage.cols, DisparityRange, disparityMap);
	cvMat2AXIvideo(disparityMap, DispMap); //write the frames to video stream
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).