我的运行环境如下:
Mac OSX EI 10.11.5
opencv 2.4.13
Xcode版本7.3.1
为什么没有在轨道栏上显示我的值作为附图。
这是因为系统问题?
感谢
main()
{
VideoCapture cap(0);
if ( !cap.isOpened() ) // if not success, exit program
{
cout << "Cannot open the cam" << endl;
return -1;
}
namedWindow("Thresholded Image", CV_WINDOW_AUTOSIZE); //create a window called "Control"
int iLowH = 0;
int iHighH = 179;
int iLowS = 0;
int iHighS = 255;
int iLowV = 0;
int iHighV = 255;
cvCreateTrackbar("LowH", "Thresholded Image", &iLowH, 179);
cvCreateTrackbar("HighH", "Thresholded Image", &iHighH, 179);
cvCreateTrackbar("LowS", "Thresholded Image", &iLowS, 255);
cvCreateTrackbar("HighS", "Thresholded Image", &iHighS, 255);
cvCreateTrackbar("LowV", "Thresholded Image", &iLowV, 255);
cvCreateTrackbar("HighV", "Thresholded Image", &iHighV, 255);
while (true)
{
Mat imgOriginal;
bool bSuccess = cap.read(imgOriginal); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
Mat imgHSV;
cvtColor(imgOriginal, imgHSV, COLOR_BGR2HSV); //Convert the captured frame from BGR to HSV
Mat imgThresholded;
inRange(imgHSV, Scalar(iLowH, iLowS, iLowV), Scalar(iHighH, iHighS, iHighV), imgThresholded); //Threshold the image
erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) );
dilate( imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) );
dilate( imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) );
erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) );
namedWindow("Thresholded Image", 0);
namedWindow("Original", CV_WINDOW_NORMAL);
resize(imgThresholded,imgThresholded, Size(imgThresholded.cols/3, imgThresholded.rows/3));
namedWindow("Thresholded Image", CV_WINDOW_AUTOSIZE);
imshow("Thresholded Image", imgThresholded); //show the thresholded image
resize(imgOriginal,imgOriginal, Size(imgOriginal.cols/3, imgOriginal.rows/3));
namedWindow("Original", CV_WINDOW_AUTOSIZE);
imshow("Original", imgOriginal); //show the original image
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
return 0;
}