Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 25th, 2013  |  syntax: None  |  size: 0.87 KB  |  views: 95  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include "opencv2/highgui/highgui.hpp"
  3. #include "opencv2/imgproc/imgproc_c.h"
  4. #include "opencv2/imgproc/imgproc.hpp"
  5. #include <stdio.h>
  6. using namespace std;
  7. using namespace cv;
  8.  
  9. int main()
  10. {
  11.  
  12. Mat newImg,img;
  13. img=imread("img.jpeg");
  14. cvtColor(img, newImg, CV_BGR2HSV);
  15.  
  16. imwrite("test.jpg", newImg);
  17.  
  18. vector<Mat> hsv_planes;
  19. split(newImg, hsv_planes); //geting the color plans of image
  20. int param = -70; // the value that I'm seting for V
  21.     for (int y = 0; y < newImg.rows; y++) {
  22.     for (int x = 0; x < newImg.cols; x++) {
  23.  
  24.         Vec3b pixel = hsv_planes[2].at<Vec3b>(y, x);
  25.         pixel[0] = 0;
  26.         pixel[1] = 0;
  27.         pixel[2] = param;
  28.  
  29.         hsv_planes[2].at<Vec3b>(y, x) = pixel;
  30.  
  31.     }
  32. }
  33.  
  34.     merge(hsv_planes, newImg);
  35. Mat imagem;
  36. cvtColor(newImg, imagem, CV_HSV2BGR);
  37.  
  38. imwrite("final.jpg", imagem);
  39.  
  40.     return 0;
  41. }
clone this paste RAW Paste Data