临海网站制作,无为网站建设,软件项目管理名词解释,如何开通网上商城操作系统#xff1a;ubuntu22.04 OpenCV版本#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言#xff1a;C11
算法描述
返回滑动条的位置。
该函数返回指定滑动条的当前位置。
cv::getTrackbarPos() 函数用于获取指定滑动条#xff08;trackbar#xff09;的当前… 操作系统ubuntu22.04 OpenCV版本OpenCV4.9 IDE:Visual Studio Code 编程语言C11
算法描述
返回滑动条的位置。
该函数返回指定滑动条的当前位置。
cv::getTrackbarPos() 函数用于获取指定滑动条trackbar的当前位置。
注释 [仅 Qt 后端] 如果滑动条附加到了控制面板则 winname 可以为空。
函数原型
int cv::getTrackbarPos
(const String trackbarname,const String winname
) 参数
参数trackbarname 滑动条的名称。参数twinname 作为滑动条父级的窗口的名称。
返回值
返回一个整数值表示滑动条的当前位置。
代码示例 #include iostream
#include opencv2/opencv.hpp// 回调函数
void onTrackbarSlide( int pos, void* userData )
{cv::Mat img *( cv::Mat* )userData;cv::Mat thresholdImg;cv::threshold( img, thresholdImg, pos, 255, cv::THRESH_BINARY );cv::imshow( Threshold Image, thresholdImg );
}int main()
{// 加载图像cv::Mat img cv::imread(/media/dingxin/data/study/OpenCV/sources/images/hawk.jpg, cv::IMREAD_GRAYSCALE );if ( img.empty() ){std::cerr Error: Image not found! std::endl;return -1;}// 创建窗口cv::namedWindow( Threshold Image );// 创建滑动条int thresholdValue 128;cv::createTrackbar( Threshold Value, Threshold Image, thresholdValue, 255, onTrackbarSlide, img );// 初始显示cv::Mat thresholdImg;cv::threshold( img, thresholdImg, thresholdValue, 255, cv::THRESH_BINARY );cv::imshow( Threshold Image, thresholdImg );// 获取滑动条的当前位置int currentPosition cv::getTrackbarPos( Threshold Value, Threshold Image );std::cout Current trackbar position: currentPosition std::endl;// 主循环while ( true ){int key cv::waitKey( 1 );if ( key 27 ){ // ESC 键break;}}// 释放资源cv::destroyAllWindows();return 0;
}运行结果