Color-based object detection using Hue and Saturation thresholding

翻译 2016年06月01日 10:33:23

函数原型:C++: int createTrackbar(const string& trackbarname, const string& winname, int* value, int count, TrackbarCallback onChange=0, void* userdata=0)

//Color_based object detection using Hue and Saturation thresholding

/*1、Program to display a video from attached default camera device 
  and detect colored blobs using H and S thresholding.
  2、Remove noise using opening and closing morphological operations*/



#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;

int hs_slider=0,low_slider=30,high_slider=100;
int low_h=30,low_s=30,high_h=100,high_s=100;
void on_hs_trackbar(int ,void *)
{
	switch (hs_slider)
	{
	case 0:
		setTrackbarPos("Low threshold","Segmentation",low_h);
		setTrackbarPos("High threshold","Segmentation",high_h);
		break;
	case 1:
		setTrackbarPos("Low threshold","Segmentation",low_s);
		setTrackbarPos("High threshold","Segmentation",high_s);
		break;
	}

}
void on_low_thresh_trackbar(int ,void *)
{
	switch(hs_slider)
	{
	case 0:
		low_h=min(high_slider-1,low_slider);
		setTrackbarPos("Low threshold","Segmentation",low_h);
		break;
	case 1:
		low_s=min(high_slider-1,low_slider);
		setTrackbarPos("Low threshold","Segmentation",low_s);
		break;
	}
}
void on_high_thresh_trackbar(int ,void *)
{
	switch(hs_slider)
	{
	case 0:
		high_h=max(low_slider+1,high_slider);
		setTrackbarPos("High threshold","Segmentation",high_h);
		break;
	case 1:
		high_s=max(low_slider+1,high_slider);
		setTrackbarPos("High threshold","Segmentation",high_s);
		break;
	}
}
int main()
{
	VideoCapture cap(0);
	if(!cap.isOpened())//check if the file was open properly
	{
		cout<<" failed to open Capture"<<endl;
		return -1;
	}
	namedWindow("Video");
	namedWindow("Segmentation");
	//creat trackbar
	createTrackbar("0.H\n1.S","Segmentation",&hs_slider,1,on_hs_trackbar);
	createTrackbar("Low threshold","Segmentation",&low_slider,255,on_low_thresh_trackbar);
	createTrackbar("High threshold","Segmentation",&high_slider,255,on_high_thresh_trackbar);
	//
	while (char(waitKey(1))!='q'&&cap.isOpened())
	{
		Mat frame,frame_thresholded,frame_hsv;
		cap>>frame;
		cvtColor(frame,frame_hsv,CV_BGR2HSV);
		//Check if the video is over
		if (frame.empty())
		{
			cout<<"Video over"<<endl;
			break;
		}
		//extract the Hue and Saturation channels
		int from_to[]={0,0,1,1};
		Mat hs(frame_hsv.size(),CV_8UC2);
		mixChannels(&frame_hsv,1,&hs,1,from_to,2);
		//check the image for a specific range of H and S
		inRange(hs,Scalar(low_h,low_s),Scalar(high_h,high_s),frame_thresholded);
		//open and close to remove noise
		Mat str_el=getStructuringElement(MORPH_ELLIPSE,Size(7,7));
		morphologyEx(frame_thresholded,frame_thresholded,MORPH_OPEN,str_el);
		morphologyEx(frame_thresholded,frame_thresholded,MORPH_CLOSE,str_el);
		imshow("Video",frame);
		imshow("Segmentation",frame_thresholded);
	}
	return 0;
}

【论文笔记】Scalable Object Detection using Deep Neural Networks

Scalable Object Detection using Deep Neural Networks Erhan, D., Szegedy, C., Toshev, A., & Anguelov...
  • xiaozhi_chen
  • xiaozhi_chen
  • 2014年03月10日 19:25
  • 7090

iOS Dev (26) 初步了解下UIColor的最常用知识

iOS Dev (26) 初步了解下UIColor的最常用知识 作者:CSDN 大锐哥地址:http://blog.csdn.net/prevention - 内置的颜色有啥? // So...
  • prevention
  • prevention
  • 2014年01月17日 00:44
  • 7289

论文提要“Scalable Object Detection using Deep Neural Networks”

论文提要“Scalable Object Detection using Deep Neural Networks”与之前主流检测方法DPM不同,论文提出了一种名为“DeepMultiBox”的方法产...
  • cv_family_z
  • cv_family_z
  • 2015年06月11日 17:03
  • 2263

Scalable Object Detection using Deep Neural Networks(泛读)

一.文献名字和作者     Scalable Object Detection using Deep Neural Networks, CVPR2014     二.阅读时间      2...
  • shengno1
  • shengno1
  • 2014年10月03日 16:43
  • 2408

整理Rapid object detection using a boosted cascade of simple features论文中的要点

整理Rapid object detection using a boosted cascade of simple features论
  • OneCodeMan
  • OneCodeMan
  • 2017年02月08日 17:51
  • 531

Adaptive Object Detection Using Adjacency and Zoom Prediction

(个人觉得本论文主要的创新就在于自适应搜索检测,对于一个可能包含小物体目标的区域再进行细分) 摘要:目标检测系统的性能依赖于精确的region proposals集合。最近一些方法使用一个神经网络结...
  • ScarecrowLiu
  • ScarecrowLiu
  • 2016年06月02日 17:10
  • 1005

Rapid object detection using a boosted cascade of simple features-简译

原文参照Paul_Viola的《Rapid object detection using a boosted cascade of simplefeatures》 本次翻译,包含简单的个人总结以方便...
  • shuzfan
  • shuzfan
  • 2015年04月06日 08:29
  • 1914

Rapid Object Detection using a Boosted Cascade of Simple Features 部分翻译

haar-like,adaboost经典论文
  • TonyShengTan
  • TonyShengTan
  • 2014年11月27日 10:11
  • 3148

IOS开发之——颜色设置

颜色设置: 指定RGB,参数是:红、绿、黄、透明度,范围是0-1 + (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green b...
  • zhenyu5211314
  • zhenyu5211314
  • 2014年04月21日 10:50
  • 4242

UIColor 进阶

多说,请先看头文件: #import #import #import #import @class UIImage; UIKIT_CLASS_AVAILABLE(2_0) @inte...
  • iukey
  • iukey
  • 2012年09月16日 23:20
  • 8698
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Color-based object detection using Hue and Saturation thresholding
举报原因:
原因补充:

(最多只允许输入30个字)