相当于OpenCV C ++接口中的cvAvg [英] Equivalent to cvAvg in the OpenCV C++ interface

查看:1444
本文介绍了相当于OpenCV C ++接口中的cvAvg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这两个链接中发出相同的问题:一个两个。我需要在图像中的小ROI上计算像素强度平均值。

I'm having the same problem issued in these two links: one, two. I need to calculate pixel intensity average on a small ROI in an image.

我选择了ROI并将图像复制到其中,所以现在我需要计算像素平均强度

I selected the ROI and copied the image in it, so now I need to calculate pixel average intensity, avoiding a loop on all of the pixels.

链接中提供的答案建议使用 CvScalar c = cvAvg(img);

The answers provided in the links suggest to use CvScalar c = cvAvg(img); but I can't find the equivalent, using the C++ interface.

你能向我指出吗?我在文档中找不到它!

Can you please point it out to me? I couldn't find it in the documentation!

推荐答案

我提供代码片段解决问题:

I provide the code snippet solving the problem:

//defines roi
cv::Rect roi( roiVertexXCoordinate, roiVertexYCoordinate, roiWidth, roiHeight );

//copies input image in roi
cv::Mat image_roi = inputImage( roi );

//computes mean over roi
cv::Scalar avgPixelIntensity = cv::mean( image_roi );

//prints out only .val[0] since image was grayscale
cout << "Pixel intensity over ROI = " << avgPixelIntensity.val[0] << endl;

这篇关于相当于OpenCV C ++接口中的cvAvg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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