OpenCV Tutorials —— Adding a Trackbar to our applications

來源:互聯網
上載者:User

標籤:style   io   ar   os   sp   for   strong   on   div   

int createTrackbar(const string& trackbarname, const string& winname, int* value, int count, TrackbarCallbackonChange=0, void* userdata=0)

Parameters:

  • trackbarname – Name of the created trackbar.  滑動條名稱
  • winname – Name of the window that will be used as a parent of the created trackbar.  添加滑條的視窗名
  • value – Optional pointer to an integer variable whose value reflects the position of the slider. Upon creation, the slider position is defined by this variable.  滑塊位置,通常定義成全域變數 ~

 

  • count – Maximal position of the slider. The minimal position is always 0.  滑塊最大位置
  • onChange – Pointer to the function to be called every time the slider changes position. This function should be prototyped as void Foo(int,void*); , where the first parameter is the trackbar position and the second parameter is the user data (see the next parameter). If the callback is the NULL pointer, no callbacks are called, but only value is updated.  回呼函數的指標(每次滑塊位置改變時調用)
  • userdata – User data that is passed as is to the callback. It can be used to handle trackbar events without using global variables. 向回呼函數傳遞的參數

Code

#include "stdafx.h"#include <cv.h>#include <highgui.h>using namespace cv;/// Global Variablesconst int alpha_slider_max = 100;int alpha_slider;double alpha;double beta;/// Matrices to store imagesMat src1;Mat src2;Mat dst;/** * @function on_trackbar * @brief Callback for trackbar */void on_trackbar( int, void* ){alpha = (double) alpha_slider/alpha_slider_max ;beta = ( 1.0 - alpha );addWeighted( src1, alpha, src2, beta, 0.0, dst);imshow( "Linear Blend", dst );}int main( int argc, char** argv ){/// Read image ( same size, same type )src1 = imread("img1.jpg");src2 = imread("you.jpg");int min_c;int min_r;min_c = src1.cols>src2.cols?src2.cols:src1.cols;min_r = src1.rows>src2.rows?src2.rows:src1.rows;src1=src1(Range(0,min_r),Range(0,min_c));src2=src2(Range(0,min_r),Range(0,min_c));if( !src1.data ) { printf("Error loading src1 \n"); return -1; }if( !src2.data ) { printf("Error loading src2 \n"); return -1; }/// Initialize valuesalpha_slider = 0;/// Create WindowsnamedWindow("Linear Blend", 1);/// Create Trackbarschar TrackbarName[50];sprintf( TrackbarName, "Alpha x %d", alpha_slider_max );createTrackbar( TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar );/// Show some stuffon_trackbar( alpha_slider, 0 );/// Wait until user press some keywaitKey(0); return 0;}

OpenCV Tutorials —— Adding a Trackbar to our applications

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.