c++ - pass the pointer of image buffer to OpenCV and change the saturation? -


i want pass pointer of image buffer, change saturation , see result immediately. change not applying in buffer , not changing.

void changesaturation(void* buffer,int width, int height) {   mat matobject(width, height, cv_8uc4, buffer);   m_matsource = matobject;   mat newmat = m_matsource.clone();    // bgr hsv   cvtcolor(matsource, matsource, cv_bgr2hsv);   for(int = 0; < newmat.rows; ++i)    {      for(int j = 0; j < newmat.cols; ++j)      {         newmat.at<cv::vec3b>(i, j)[1] = 255; //saturationvalue;      }    }  // hsv bgr  cvtcolor(newmat, m_matsource, cv_hsv2bgr); // here m_matsource->data change 

}

how can apply change on buffer?

i refactored code when trying reproduce problem , in process fixed it. cloned source newmat changed color space of original image , proceed ignore new modified image. try out:

void changesaturation(mat& image) {     mat result(image.rows, image.cols, image.type());      // bgr hsv     cvtcolor(image, result, cv_bgr2hsv);     for(int = 0; < result.rows; ++i)     {         for(int j = 0; j < result.cols; ++j)             result.at<cv::vec3b>(i, j)[1] = 255; //saturationvalue;     }  // hsv bgr     cvtcolor(result, result, cv_hsv2bgr); // here m_matsource->data change      namedwindow("original");     imshow("original",image);      namedwindow("duplicate");     imshow("duplicate",result); }   int main() {     mat image;      image = imread("c:/users/public/pictures/sample pictures/desert.jpg");      changesaturation(image);     waitkey(0); } 

edit

to modify input image:

void changesaturation(mat& image) {     // bgr hsv     cvtcolor(image, image, cv_bgr2hsv);     for(int = 0; < image.rows; ++i)     {         for(int j = 0; j < image.cols; ++j)             image.at<cv::vec3b>(i, j)[1] = 255; //saturationvalue;     }      // hsv bgr     cvtcolor(image, image, cv_hsv2bgr); // here m_matsource->data change } 

next edit

this has (almost) original function signature:

void changesaturation(uchar* buffer, int rows, int cols, int type) {     mat image(rows, cols, type, buffer);     mat result;     // bgr hsv     cvtcolor(image, result, cv_bgr2hsv);     for(int = 0; < result.rows; ++i)     {         for(int j = 0; j < result.cols; ++j)             result.at<cv::vec3b>(i, j)[1] = 255;     }      // hsv bgr     cvtcolor(result, image, cv_hsv2bgr); }  int main() {     mat image;      image = imread("c:/users/public/pictures/sample pictures/desert.jpg");      changesaturation(image.data, image.rows, image.cols, image.type());      imshow("original",image);     waitkey(0); } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -