- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在“OpenCV 2 计算机视觉应用程序编程手册”一书第 4 章中运行一个示例。calcHist 返回的只有 2 个直方图是黑色的,并且遵循源代码。运行结果如下图。
ColorHistogram() {
// Prepare arguments for a color histogram
histSize[0]= histSize[1]= histSize[2]= 256;
hranges[0]= 0.0; // BRG range
hranges[1]= 255.0;
ranges[0]= hranges; // all channels have the same range
ranges[1]= hranges;
ranges[2]= hranges;
channels[0]= 0; // the three channels
channels[1]= 1;
channels[2]= 2;
}
...
// Computes the 2D ab histogram.
// BGR source image is converted to Lab
cv::MatND getabHistogram(const cv::Mat &image) {
cv::MatND hist;
// Convert to Lab color space
cv::Mat lab;
cv::cvtColor(image,lab,CV_BGR2Lab);
// Prepare arguments for a 2D color histogram
hranges[0]= -128.0;
hranges[1]= 127.0;
channels[0]= 1; // the two channels used are ab
channels[1]= 2;
// Compute histogram
cv::calcHist(&lab,
1, // histogram of 1 image only
channels, // the channel used
cv::Mat(), // no mask is used
hist, // the resulting histogram
2, // it is a 2D histogram
histSize, // number of bins
ranges // pixel value range
);
return hist;
}
错误在哪里?我想不明白。将图像转换为 Lab 格式时 cvtColor(...) 函数是否出错?
最佳答案
代码有错误。您正在为 channel 分配随机值。在 calchist() 中将范围更改为 hranges。试试这个:
cv::MatND getabHistogram(const cv::Mat &image) {
cv::MatND hist;
// Convert to Lab color space
cv::Mat lab;
cv::cvtColor(image,lab,CV_BGR2Lab);
// Prepare arguments for a 2D color histogram
hranges[0]= -128.0;
hranges[1]= 127.0;
channels[0]= 1; // the two channels used are ab
channels[1]= 2;
// Compute histogram
cv::calcHist(&lab,
1, // histogram of 1 image only
channels, // the channel used
cv::Mat(), // no mask is used
hist, // the resulting histogram
2, // it is a 2D histogram
histSize, // number of bins
hranges // pixel value range
);
return hist;
关于c++ - opencv calcHist 在使用 cvtColor 后返回黑色直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48576829/
我有这样的事情: import numpy as np import cv2 as cv from matplotlib import pyplot as plt import numpy.polyn
我正在使用 calcHist 函数计算图像的颜色直方图。我正在开发一个简单的图像匹配应用程序,我正在尝试使用颜色直方图作为图像描述符来查找相似图像。 这是定义: void calcHist(const
尝试使用带掩码的 calcHist 时出现此错误:error: (-215) mask.size() == imsize && mask.channels() == 1 in function his
我正在努力学习equalization of histograms , 我当然知道有 histogram equalization in OpenCV .我是iterating over the Ma
我正在尝试使用 OpenCV 的 Emgu C# 包装器为图像的反向投影创建直方图。我有以下 OpenCV C++ 代码,我正在尝试将其转换为 Emgu C#: char* filename = (c
我有这段代码用于计算和绘制图像的直方图。 colors = ('b', 'g', 'r') for i, col in enumerate(colors): hist = cv2.calcHi
在尝试使用 cv2.calcHist() 时,我遇到了以下不明确的错误 >>> img array([ 1., 2., 3., 4., 5.]) >>> cv2.calcHist( [img]
我试图了解 cvCalcHist 之间的区别,openCV c 版本 和 calcHist 中计算图像直方图的方法>,openCV c++ version 中计算图像直方图的方法。 openCV c版
我试图从 OpenCV 中的彩色(3 channel )图像中获取直方图,但每次我都像这样执行 calcHist 直方图: //int histSize[3]; //float hranges[2];
我已经多次阅读 calcHist() 的文档,但我认为我对 OpenCV 的缺乏经验和生疏的编程技能完全使我无法理解它。 我正在计算 HSV 图像(Hue 或 channel [0])的一个 chan
我想做的是编写一个函数来计算灰度图像的直方图,其中转发的 Bins 数 (anzBin) 直方图范围被划分为。然后我运行图像像素以匹配它们将值分配给不同的 Bins,如果某个值适合,则将 Bin 的值
我正在尝试让一些 C++ 代码在我的 Android 设备上运行;但是,我遇到了 Mat 类型的一个小问题。我在用着。我尝试转换的代码如下(第二个函数调用第一个): static Mat histc_
我在“OpenCV 2 计算机视觉应用程序编程手册”一书第 4 章中运行一个示例。calcHist 返回的只有 2 个直方图是黑色的,并且遵循源代码。运行结果如下图。 ColorHistogram()
我正在使用上面的代码从灰度图像计算直方图;它工作正常。 cv::Mat imgSrc = cv::imread("Image.jpg", cv::IMREAD_UNCHANGED); cv::Mat
我正在尝试计算仅由一行组成的矩阵的直方图。我使用 OpenCV3.1 在 VS2015 中编写了这段代码: //Create matrix stromal pop cv::Mat stromalHis
我想计算图像的颜色直方图,但只考虑特定像素(我知道其二维坐标)。 是否可以使用 calcHist 指定仅应考虑这些具体像素(而不是整个 cv::Mat 和其中的所有像素)?如果没有,是否可以创建一个新
我是计算机视觉的新手,这是我的第一份作业。我正在尝试创建与文件夹中的每个图像相对应的 rgb 直方图。假设我在 test 文件夹(位于我当前的工作目录中)中有 10 张图片。我想为每个图像创建 10
我有计算 hsv 和 yuv 图像直方图的代码。由于我试图单独获取与亮度对应的值,因此我想要来自 hsv 图像的“v” channel 值和来自 yuv 图像的亮度(“y”) channel 值。这是
这里有很多关于 OpenCV 中的 calcHist 的问题,但我找不到我的问题的答案,并且已经多次阅读文档,所以希望有人可以通过以下代码发现我的问题: //the setup is that I'v
我正在尝试使用以下代码: cv::MatND hist; cv::Mat image = cv::imread("image.bmp"); float *range = new
我是一名优秀的程序员,十分优秀!