- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 OpenCV C++ 在视频/实时流/图像中执行特征检测。视频不同部分的光照条件不同,导致在将 RGB 图像转换为二值图像时某些部分被忽略。
视频特定部分的照明条件也会随着视频的播放而变化。我尝试了“直方图均衡”功能,但没有帮助。
我在以下链接中获得了 MATLAB 中的有效解决方案:
http://in.mathworks.com/help/images/examples/correcting-nonuniform-illumination.html
但是,上述链接中使用的大部分函数在 OpenCV 中不可用。
您能否建议在 OpenCV C++ 中替代此 MATLAB 代码?
最佳答案
OpenCV 在框架中提供了自适应阈值范例:http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#adaptivethreshold
函数原型(prototype)如下:
void adaptiveThreshold(InputArray src, OutputArray dst,
double maxValue, int adaptiveMethod,
int thresholdType, int blockSize, double C);
前两个参数是输入图像和存储输出阈值图像的位置。 maxValue
是分配给输出像素的阈值,如果它通过标准,adaptiveMethod
是用于自适应阈值的方法,thresholdType
是您要执行的阈值类型(稍后详述),blockSize
是要检查的窗口的大小(稍后详述),C
是要从每个窗口中减去的常量.我从来没有真正需要使用它,我通常将它设置为 0。
adaptiveThreshold
的默认方法是分析 blockSize x blockSize
窗口并计算此窗口内的平均强度减去 C
。如果这个窗口的中心高于平均强度,输出图像的输出位置中的这个对应位置设置为 maxValue
,否则相同位置设置为 0。这应该对抗非均匀照明问题,您不是对图像应用全局阈值,而是对局部像素邻域执行阈值处理。
您可以阅读有关其他参数的其他方法的文档,但要开始使用,您可以执行以下操作:
// Include libraries
#include <cv.h>
#include <highgui.h>
// For convenience
using namespace cv;
// Example function to adaptive threshold an image
void threshold()
{
// Load in an image - Change "image.jpg" to whatever your image is called
Mat image;
image = imread("image.jpg", 1);
// Convert image to grayscale and show the image
// Wait for user key before continuing
Mat gray_image;
cvtColor(image, gray_image, CV_BGR2GRAY);
namedWindow("Gray image", CV_WINDOW_AUTOSIZE);
imshow("Gray image", gray_image);
waitKey(0);
// Adaptive threshold the image
int maxValue = 255;
int blockSize = 25;
int C = 0;
adaptiveThreshold(gray_image, gray_image, maxValue,
CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY,
blockSize, C);
// Show the thresholded image
// Wait for user key before continuing
namedWindow("Thresholded image", CV_WINDOW_AUTOSIZE);
imshow("Thresholded image", gray_image);
waitKey(0);
}
// Main function - Run the threshold function
int main( int argc, const char** argv )
{
threshold();
}
关于c++ - opencv C++ 中非均匀光照物体的检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31375948/
我喜欢在 Lisp、Python 或 JavaScript 等(通常是动态的)语言中可以使用 boolean 运算符而不是条件来编写的简洁代码,如典型的: x = someString or "def
具体来说,我将 WPF 与 MVVM 一起使用。我有一个 MainWindow,它是一个 WPF 窗口,所有操作都在其中发生。它为其属性、命令等使用相应的 View 模型类。 我在 Applicati
对于我从 VB6 移植的应用程序,我有几个关于 CLS 合规性的烦人的编译器警告,包括: Name '_AnIdentifier' is not CLS-Compliant. Type of para
Module Unix 包含 time 函数来获取自 Epoch 以来的秒数,但是是否有一种独立于平台的方式来获取相同的值并确保代码在非-Unix 部署? 最佳答案 尽管有它的名字,Unix modu
我有一个 R 函数,它试图将每个“单词”的第一个字母大写 proper = function(x){ gsub("(? proper("Māori") [1] "MāOri" 显然,RE 引擎认为
我有一个包含两列的表格。一个是 auto_increment 说 columnA 而另一个是非 auto_increment 说 columnB。我想在 columnB 中执行两种类型的插入操作: 插
我遇到了这个错误,但无法调试它 helpers.c:136:1: error: control may reach end of non-void function IDE 在最后一行中说} 这是我的
我想检查一个数组在 C 中是否按 acs 或 desc 顺序排序。这是使用 mpicc -Wall -o file file.c 编译的结果,因为我稍后在代码中使用 MPI 库。 mypractice
我想了解编译器对 C 中的非 volatile 变量有哪些限制(如果有的话)。 我不确定这是否属实,但有人告诉我,如果您有以下代码: int x; ... void update_x() { lo
我的代码在 IE 中有效,但在 Firefox 中无效。我试图让 onmousedown 和 onmouseup 事件以及 swapFE、swapEF 和 setUpTranslation 函数在 I
我的问题是.. 是否可以在非 root 设备上静默自动更新应用程序?如果设备已 Root ,则它会使用 super 用户权限更新我的应用程序,否则不会。请回复谢谢! 最佳答案 无法在非 Root 设备
阅读了 PropertyAnimator 的文档后,似乎只要满足以下条件之一,我们就可以为每个对象设置动画, 如果您有权限,请将 setter 方法添加到类中。 使用您有权更改的包装器类,并让该包装器
所以我正在制作移动应用程序,并希望使用相同的 URL 创建链接以激活 iOS 和 Android 中的内容。我已经知道该怎么做了。我对 android 的 Intent 是这样的:
这个问题很接近我的问题,但又不完全是:List minimum in Python with None? .我需要考虑到列表中所有值都为 None 的可能性。 我有一种情况,我必须在数据库中查找一些数
如何从 Pandas 数据框中获取非“NaN”值的索引? 我的数据框是 A b c 0 1 q1 1 1 2 NaN 3 2 3 q2
对于数据框 df = pd.DataFrame([[np.nan, 3.0, 7.0], [0.0, 5.0, 8.0], [0.0, 0.0, 0.0], [1.0, 3.0, np.nan], [
我在 Android 中播放视频之前对其进行解密。当我解密它时,我想将它存储在 Android 私有(private)文件夹中,这样其他应用程序和用户就无法访问它 - 我已经查找了一些看起来像这样的代
我有一个非常大的 csv 文件,如下所示: 关键词,印象 下载 juegos gratis,951 パソコン kakaku com,451 公司 session ,155 租车,356
我有一个继承自 AbstractType 的表单生成器类,我需要解析如下路径: $uri = $router->generate('blog_show', array('slug' => 'my-bl
我想从 Android 应用程序中的一个原始文本文件中读取一些文本,并在应用程序中显示该文本文件中的一行。小部件。 对于 MainActivity,我编写了一个使用以下代码获取 InputStream
我是一名优秀的程序员,十分优秀!