opencv 3.0
2016-01-23 22:59
288 查看
#include <iostream> #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "cv.h" #include "highgui.h" using namespace cv; using namespace std; int main( int argc, char** argv ) { //VideoCapture cap(0); //capture the video from web cam //if ( !cap.isOpened() ) // if not success, exit program //{ // cout << "Cannot open the web cam" << endl; // return -1; //} namedWindow("Control", CV_WINDOW_AUTOSIZE); //create a window called "Control" int iLowH = 25; int iHighH = 67; int iLowS = 42; int iHighS = 180; int iLowV = 0; int iHighV = 255; /*int iLowH = 15; int iHighH = 26; int iLowS = 101; int iHighS = 255; int iLowV = 86; /* int iHighV = 255;*/ /*int iLowH = 0; int iHighH = 4; int iLowS = 77; int iHighS = 255; int iLowV = 40; int iHighV = 170;*/ //Create trackbars in "Control" window cvCreateTrackbar("LowH", "Control", &iLowH, 179); //Hue (0 - 179) cvCreateTrackbar("HighH", "Control", &iHighH, 179); cvCreateTrackbar("LowS", "Control", &iLowS, 255); //Saturation (0 - 255) cvCreateTrackbar("HighS", "Control", &iHighS, 255); cvCreateTrackbar("LowV", "Control", &iLowV, 255); //Value (0 - 255) cvCreateTrackbar("HighV", "Control", &iHighV, 255); while (true) { Mat imgOriginal; imgOriginal=cvLoadImage("E:\\555.jpg"); Mat imgHSV; vector<Mat> hsvSplit; cvtColor(imgOriginal, imgHSV, COLOR_BGR2HSV); //Convert the captured frame from BGR to HSV ////因为我们读取的是彩色图,直方图均衡化需要在HSV空间做 split(imgHSV, hsvSplit); equalizeHist(hsvSplit[2],hsvSplit[2]); merge(hsvSplit,imgHSV); Mat imgThresholded; inRange(imgHSV, Scalar(iLowH, iLowS, iLowV), Scalar(iHighH, iHighS, iHighV), imgThresholded); //Threshold the image //开操作 (去除一些噪点) Mat element = getStructuringElement(MORPH_RECT, Size(5, 5)); morphologyEx(imgThresholded, imgThresholded, MORPH_OPEN, element); //闭操作 (连接一些连通域) morphologyEx(imgThresholded, imgThresholded, MORPH_CLOSE, element); CvMemStorage* storage = cvCreateMemStorage(); CvSeq * circles=NULL; //Canny(imgThresholded,imgThresholded,3, 3); imshow("Thresholded Image", imgThresholded); //show the thresholded image imshow("Original", imgOriginal); //show the original image char key = (char) waitKey(300); if(key == 27) break; } return 0; }
相关文章推荐
- linux 嵌入式环境使用iptables防火墙的一些体验
- docker镜像
- CentOS 5与6的启动流程
- Linux命令
- linux学习笔记(二)--linux字符界面操作基础
- AOP注解配置
- docker share
- OpenStack设计与实现(二)Libvirt简介与实现原理
- linux平台从源码安装git
- linux中的内核模块以及模块操作工具modprobe|insmod|rmmod|depmod|lsmod|modinfo等学习小结
- shell脚本通过expect脚本实现自动输入密码
- CentOS下modelsim 10.2c install & crack
- linux一些名词
- 推荐一个免费的论文查重网站
- hadoop-1.x的运行实例
- CentOS6.5上安装MySQL5.6
- arch linux安装玩fcitx后无法激活解决
- linux下samba共享服务器搭建
- linux下goagent证书问题终极解决方案!
- 5.7 copy--简单拷贝和深度拷贝对象