#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\opencv.hpp>
#include <vector>
using namespace std;
using namespace cv;
int H_thre = 146;
int S_thre = 103;
int V_thre = 220;
void H_treament(int pos)
{
H_thre = pos;
}
void S_treament(int pos)
{
S_thre = pos;
}
void V_treament(int pos)
{
V_thre = pos;
}
int main()
{
VideoCapture capture(0); //创建VideoCapture对象
Mat frame; //用来存放读取的视频序列
Mat HSV;
vector<Mat> channels;
namedWindow("video");
namedWindow("hsv");
namedWindow("creat_trackbar", 1); //定义窗口
cvCreateTrackbar("H", "creat_trackbar", &H_thre, 255, H_treament);
cvCreateTrackbar("S", "creat_trackbar", &S_thre, 255, S_treament); //创建滑动条
cvCreateTrackbar("V", "creat_trackbar", &V_thre, 255, V_treament);
while (!stop)
{
if (!capture.read(frame))//读取
{
break;
}
cvtColor(frame, HSV, CV_BGR2HSV); //转hsv图
imshow("hsv", HSV); //hsv图显示
split(HSV, channels); //分离通道
Mat H = channels.at(0);
Mat S = channels.at(1);
char c = cvWaitKey(33);
if (c == 27)break;
}
capture.release();
}
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\opencv.hpp>
#include <vector>
using namespace std;
using namespace cv;
int H_thre = 146;
int S_thre = 103;
int V_thre = 220;
void H_treament(int pos)
{
H_thre = pos;
}
void S_treament(int pos)
{
S_thre = pos;
}
void V_treament(int pos)
{
V_thre = pos;
}
int main()
{
VideoCapture capture(0); //创建VideoCapture对象
if (!capture.isOpened()) //判断是否打开摄像头
return 1;
bool stop(false);Mat frame; //用来存放读取的视频序列
Mat HSV;
vector<Mat> channels;
namedWindow("video");
namedWindow("hsv");
namedWindow("creat_trackbar", 1); //定义窗口
cvCreateTrackbar("H", "creat_trackbar", &H_thre, 255, H_treament);
cvCreateTrackbar("S", "creat_trackbar", &S_thre, 255, S_treament); //创建滑动条
cvCreateTrackbar("V", "creat_trackbar", &V_thre, 255, V_treament);
while (!stop)
{
if (!capture.read(frame))//读取
{
break;
}
cvtColor(frame, HSV, CV_BGR2HSV); //转hsv图
imshow("hsv", HSV); //hsv图显示
split(HSV, channels); //分离通道
Mat H = channels.at(0);
Mat S = channels.at(1);
Mat V = channels.at(2);
threshold(H, H, H_thre, 255, CV_THRESH_BINARY);
threshold(S, S, S_thre, 255, CV_THRESH_BINARY); //滑动条
threshold(V, V, V_thre, 255, CV_THRESH_BINARY);
imshow("H", H);
imshow("S", S);
imshow("V", V);char c = cvWaitKey(33);
if (c == 27)break;
}
capture.release();
}