您的位置:首页 > 运维架构

opencv——inRange

2016-05-24 10:06 471 查看
#include <opencv2\opencv.hpp>
#include <iostream>

using namespace cv;

void callback1(int pos, void*)
{
std::cout << "hmin" << pos << std::endl;
}
void callback2(int pos, void*)
{
std::cout << "smin" << pos << std::endl;
}
void callback3(int pos, void*)
{
std::cout << "vmin" << pos << std::endl;
}
void callback4(int pos, void*)
{
std::cout << "hmax" << pos << std::endl;
}
void callback5(int pos, void*)
{
std::cout << "smax" << pos << std::endl;
}
void callback6(int pos, void*)
{
std::cout << "vmax" << pos << std::endl;
}
int main()
{
Mat src, hsv, dst;
int hmin = 0;
int smin = 0;
int vmin = 0;
int hmax = 255;
int smax = 255;
int vmax = 255;

src = imread("../data/baboon.jpg");
imshow("src", src);
cvtColor(src, hsv, CV_RGB2HSV);
createTrackbar("hmin", "src", &hmin, 256, callback1);
createTrackbar("smin", "src", &smin, 256, callback2);
createTrackbar("vmin", "src", &vmin, 256, callback3);
createTrackbar("hmax", "src", &hmax, 256, callback4);
createTrackbar("smax", "src", &smax, 256, callback5);
createTrackbar("vmax", "src", &vmax, 256, callback6);
while (1)//循环包裹,刷新图像
{
inRange(hsv, Scalar(hmin, smin, vmin), Scalar(hmax, smax, vmax), dst);
imshow("dst", dst);

int c = waitKey(10);
if (c == 'q')break;
}

}
以上是代码,主要练习inRange函数
createTrackbar可以while循环刷新图像,替代回调函数。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: