Slider & Mouse & Button(QT_CHECKBOX, QT_RADIOBOX, QT_PUSH_BUTTON)

Slider

  1. createTrackbar("Lena", "Lena", &blurAmount, 30, onChange, &lena);
  2.  
  3. onChange(blurAmount, &lena);
  4.  
  5. static void onChange(int pos, void* userInput)
  6. {
  7. 	if(pos <= 0)
  8. 		return;
  9. 	// Aux variable for result
  10. 	Mat imgBlur;
  11.  
  12. 	// Get the pointer input image
  13. 	Mat* img= (Mat*)userInput;
  14.  
  15. 	// Apply a blur filter
  16. 	blur(*img, imgBlur, Size(pos, pos));	
  17.  
  18. 	// Show the result
  19. 	imshow("Lena", imgBlur);
  20. }

Mouse

  1. setMouseCallback("Lena", onMouse, &lena);
  2.  
  3. static void onMouse( int event, int x, int y, int, void* userInput )
  4. {
  5. 	if( event != EVENT_LBUTTONDOWN )
  6. 	        return;
  7.  
  8. 	// Get the pointer input image
  9. 	Mat* img= (Mat*)userInput;
  10.  
  11. 	// Draw circle
  12. 	circle(*img, Point(x, y), 10, Scalar(0,255,0), 3);
  13.  
  14. 	// Call on change to get blurred image
  15. 	onChange(blurAmount, img);
  16.  
  17. }

Button(QT_CHECKBOX, QT_RADIOBOX, QT_PUSH_BUTTON)

  1.  
  2. void grayCallback(int state, void* userData)
  3. {
  4. 	applyGray= true;
  5. 	applyFilters();
  6. }
  7. void bgrCallback(int state, void* userData)
  8. {
  9. 	applyGray= false;
  10. 	applyFilters();
  11. }
  12.  
  13. void blurCallback(int state, void* userData)
  14. {
  15. 	applyBlur= (bool)state;
  16. 	applyFilters();
  17. }
  18.  
  19. void sobelCallback(int state, void* userData)
  20. {
  21. 	applySobel= !applySobel;
  22. 	applyFilters();
  23. }
  24.  
  25. 	createButton("Blur", blurCallback, NULL, QT_CHECKBOX, 0);
  26.  
  27. 	createButton("Gray",grayCallback,NULL,QT_RADIOBOX, 0);
  28. 	createButton("RGB",bgrCallback,NULL,QT_RADIOBOX, 1);
  29.  
  30. 	createButton("Sobel",sobelCallback,NULL,QT_PUSH_BUTTON, 0);

Leave a Reply

Your email address will not be published. Required fields are marked *