opencv统计二值图黑白像素个数
#include "iostream"
#include "queue"
#include "Windows.h" #include <opencv2/ml/ml.hpp>
#include "opencv2/opencv.hpp"
#include "Windows.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml.hpp"
#include "opencv/cv.h"
#include "opencv/ml.h"
#include "opencv/highgui.h"
#include "opencv/cvaux.h"
#include "opencv/cvwimage.h"
#include "opencv/cxcore.h"
#include "opencv/cxmisc.h"
#include "opencv2/cvconfig.h"
#define MAX 30 using namespace cv;
using namespace std;
int color[]; int main(int argc, char *argv[]) {
cv::Mat frame;
cv::Mat back;
cv::Mat fore;
//cv::VideoCapture cap("C:\\C_C++ EX8 code\\Video\\MyVideo.wmv");
cv::VideoCapture cap(0);
cv::Ptr<BackgroundSubtractorMOG2> bg = createBackgroundSubtractorMOG2(); bg->setNMixtures(3);
//bg.bShadowDetection = false;
std::vector<std::vector<cv::Point> > contours; cv::namedWindow("Frame");
cv::namedWindow("Background"); while(1)
{
cap >> frame;
//bg.operator()(frame, fore);
bg->apply(frame, fore,0.01);
cv::erode(fore, fore, cv::Mat());
cv::dilate(fore, fore, cv::Mat());
bg->getBackgroundImage(back);
//cv::findContours(fore, contours, CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
//cv::drawContours(frame, contours, -1, cv::Scalar(0, 0, 255), 2);
threshold(fore, fore, 20, 250, CV_THRESH_BINARY_INV);
//---------------------------------------------------------------
int nRow = fore.rows;
int nCol = fore.cols;
//imshow("img", binaryimg);
memset(color, 0, sizeof(color));
for (int i = 0; i < nRow; i++)
{
uchar *data = fore.ptr<uchar>(i);
for (int j = 0; j < nCol; j++)
{
if (*data == 0)
color[j]++;
*data++;
}
} int high = 300;
Mat histimg(high, nCol, CV_8UC3);
for (int j = 0; j < nCol; j += 2)
{
line(histimg, Point(j, high - color[j]), Point(j, high), Scalar(0, 0, 250), 1);
}
imshow("Hist", histimg);
//---------------------------------------------------------------
//---------------------------------------------------------------
cv::imshow("Foreground", fore);
cv::imshow("Frame", frame);
cv::imshow("Background", back);
if (cv::waitKey(40) >= 0)
break;
}
return 0;
}
opencv统计二值图黑白像素个数的更多相关文章
- 使用OpenCV查找二值图中最大连通区域
http://blog.csdn.net/shaoxiaohu1/article/details/40272875 使用OpenCV查找二值图中最大连通区域 标签: OpenCVfindCoutour ...
- opencv删除二值图中较小的噪点色块
CvSeq* contour = NULL; double minarea = 100.0; double tmparea = 0.0; CFileDialog dlg(true); if (dlg. ...
- 超越OpenCV速度的MorphologyEx函数实现(特别是对于二值图,速度是CV的4倍左右)。
最近研究了一下opencv的 MorphologyEx这个函数的替代功能, 他主要的特点是支持任意形状的腐蚀膨胀,对于灰度图,速度基本和CV的一致,但是 CV没有针对二值图做特殊处理,因此,这个函数对 ...
- S0.4 二值图与阈值化
目录 二值图的定义 二值图的应用 阈值化 二值化/阈值化方法 1,无脑简单判断 opencv3函数threshold()实现 2,Otsu算法(大律法或最大类间方差法) OpenCV3 纯代码实现大津 ...
- 用 Python 通过马尔可夫随机场(MRF)与 Ising Model 进行二值图降噪
前言 这个降噪的模型来自 Christopher M. Bishop 的 Pattern Recognition And Machine Learning (就是神书 PRML……),问题是如何对一个 ...
- zw·准专利·高保真二值图细部切分算法
zw·准专利·高保真二值图细部切分算法 高保真二值图细部切分算法,是中国字体协会项目的衍生作品. 说准专利算法,是因为对于图像算法的标准不了解,虽然报过专利,但不是这方面的,需要咨询专 ...
- c语言实现灰度图转换为二值图
将上篇得到的灰度图转换为二值图,读取像素数据,低于某一值置0,否则设置为255,为得到更好的效果不同图片应采用不同的值 /* 2015年6月2日11:16:22 灰度图转换为二值图 blog:http ...
- BMP彩色转成黑色二值图
一天半把彩色bmp转成黑白了. 原理是: 第一步:读出位图数据的偏移位置:即第11个字节,用fseek即可. 然后将偏移位置之前的数据全部写入新的bmp图中. 第二步:用fseek移到位图数据这前,判 ...
- opencv 删除二值化图像中面积较小的连通域
对于上图的二值化图像,要去除左下角和右上角的噪点,方法:使用opencv去掉黑色面积较小的连通域. 代码 CvSeq* contour = NULL; double minarea = 100.0; ...
随机推荐
- CURL函数的GET和POST方式的两种写法(实现ajax跨域调用)
POST请求 function curl_post($url='',$postdata='',$options=array()){ $ch=curl_init($url); curl_setopt($ ...
- DecimalFormat类
DecimalFormat类也是Format的一个子类,主要作用是格式化数字. 在格式化数字的时候比直接使用NumberFormat更加方便,因为可以直接指定按用户自定义的方式进行格式化操作,与Sim ...
- Java工厂设计模式
程序在接口和子类之间加入一个过渡类,通过此过渡类端取得接口的实例化对象,一般都会称这个过渡端为工厂类 //=============================================== ...
- FingerGestures for Unity3D
FingerGestures http://fingergestures.fatalfrog.com
- Shared Library Search Paths
在使用CodeLite编译动态库的时候,可以通过在Linker > Linker Options中添加: -install_name @executable_path/libXXX.so 的方式 ...
- JavaScript 函数参数传递到底是值传递还是引用传递
tips:这篇文章是听了四脚猫的js课程后查的,深入的理解可以参看两篇博客: JavaScript数据类型--值类型和引用类型 JavaScript数据操作--原始值和引用值的操作本质 在传统的观念里 ...
- 改变Vim在iTerm2中的光标
vim ~/.vimrc 添加 " Change cursor shape between insert and normal mode in iTerm2.appif $TERM_PROG ...
- JS网页顶部进度条demo
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- SVN使用教程总结[转]
SVN使用教程总结 SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版本,这就需要程序员有效的管理代码,在需要的时候可以迅速,准确取出相应的版本. Sub ...
- asp.net mvc 实现博客的时间分类管理
先看效果 这个其实用c#实现起来比较简单: Sides = bllSession.IArticleBLL.GetList("") .Select(a => a.Time) . ...