UMat in ACF(opexcv学习心得一)

今天初次接触关于恩智浦的芯片,发现里面涉及opexcv部分知识,头疼不已,现将学习的记录下吧
1、读入图片
我们通过opencv读入图片,然后转换成opexcv数据类型Vsdk Umat

vsdk::UMat image = cv::imread("in_color_256x256.png", CV_LOAD_IMAGE_COLOR).getUMat(cv::ACCESS_RW);

// read the image via OpenCV, internally convert to vsdk UMat
// during conversion, the non-OAL memory is detected, UMat allocates OAL Memory and copies data to be used in vsdk

2、保存图片

// If the read image isn't contiguous (allocated on heap) when retyped to "image", this issue is detected, OAL memory is newly allocated and data copied internally
// Fast data copy TBD
{
vsdk::UMat image = cv::imread("in_color_256x256.png",
CV_LOAD_IMAGE_COLOR).getUMat(cv::ACCESS_RW);
// ... image is safe to be used by HW IP
cv::imwrite("out_color_256x256.png", (cv::UMat)image);
}

3、内存分配问题

{
vsdk::UMat image; // An empty UMat instance is created
image = vsdk::UMat(HEIGHT, WIDTH, DATA_TYPE);
// When created, memory is allocated via OAL
{
vsdk::UMat image2 = image;
// When assigned, no change happens in underlying structure,
// reference count is increased
}
} // When destroyed last reference, the data are freed from OAL heap

4、UMat in ACF

vsdk::UMat image = cv::imread("in_color_256x256.png", CV_LOAD_IMAGE_COLOR).getUMat(cv::ACCESS_RW);
if (!image.empty())
{
// Init the rest of ports
vsdk::UMat out(image.rows, image.cols, VSDK_CV_8UC3);
vsdk::UMat dataThreshold(1, 1, VSDK_CV_8UC1);
vsdk::UMat dataMarkColorChannel(1, 1, VSDK_CV_8UC1);
// Init the algorithm parameters. Note the Mat is created just for this
// call,
// it's destroyed afterwards and flushed
dataThreshold.getMat(OAL_USAGE_CACHED).at<unsigned char>(0) = THRESHOLD;
dataMarkColorChannel.getMat(OAL_USAGE_CACHED).at<unsigned char>(0) =
COLOR_CHANNEL;
// Init the ACF process
APU_FAST9_COLOR process;
lRetVal |= process.Initialize();
lRetVal |= process.ConnectIO("INPUT", image);
lRetVal |= process.ConnectIO("THRESHOLD", dataThreshold);
lRetVal |= process.ConnectIO("MARK_COLOR_CHANNEL", dataMarkColorChannel);
lRetVal |= process.ConnectIO("OUTPUT", out);
// execute
lRetVal |= process.Start();
lRetVal |= process.Wait();
// Save the output
cv::imwrite("out_color_256x256.png", (cv::UMat)out);
}

SDI视频读取

/* SDI frame processing */
sdi_grabber lGrabber;
// ... SDI init
// Grabbing loop
while(1)
{
SDI_Frame lFrame = lGrabber.FramePop();
// UMat is in lFrame.UMat
if (!lFrame.mUMat.empty()
{
// UMat processing
*****************************
        处理算法
********************************
}
// We need to push the buffer back
lGrabber.FramePush(lFrame);
}

猜你喜欢

转载自blog.csdn.net/xiao__run/article/details/81484102
今日推荐