c++ - Changing brightness and contrast of an image -
please have @ following code
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace std; using namespace cv; mat change(mat m); int main() { mat image = imread("c:/users/public/pictures/sample pictures/penguins.jpg"); mat copy = mat::zeros(image.size(),image.type()); mat changedimage = change(copy); namedwindow("image"); imshow("image",changedimage); waitkey(0); } mat change(mat m) { int cols = m.cols; int rows = m.rows; double alpha = 2.2; int beta = 50; for(int i=0;i<rows;i++) { for(int c=0;c<cols;c++) { m.at<vec3b>(rows,c)[0] = saturate_cast<uchar>(alpha* (m.at<vec3b>(rows,cols)[0]) + beta); m.at<vec3b>(rows,c)[1] = saturate_cast<uchar>(alpha* (m.at<vec3b>(rows,cols)[1]) + beta); m.at<vec3b>(rows,c)[2] = saturate_cast<uchar>(alpha* (m.at<vec3b>(rows,cols)[2]) + beta); } } return m; } this compiles fine, when run this, following error
opencv error: assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)si ze.p[0] && (unsigned)(i1*datatype<_tp>::channels) < (unsigned)(size.p[1]*channel s()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((datatype<_tp>::depth) & ((1 << 3 ) - 1))*4) & 15) == elemsize1()) in unknown function, file c:\opencv\build\inclu de\opencv2\core\mat.hpp, line 534 why getting this? guess have done correctly. please help.
try code.
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace std; using namespace cv; mat change(mat m); int main() { mat image = imread("c:/users/public/pictures/sample pictures/penguins.jpg"); mat changedimage = change(image); //modified namedwindow("image"); imshow("image",changedimage); waitkey(0); } mat change(mat m) { int cols = m.cols; int rows = m.rows; double alpha = 2.2; int beta = 50; for(int i=0;i<rows;i++) { for(int c=0;c<cols;c++) { m.at<vec3b>(i,c)[0] = saturate_cast<uchar>(alpha* (m.at<vec3b>(i,c))[0]) + beta); //modified m.at<vec3b>(i,c)[1] = saturate_cast<uchar>(alpha* (m.at<vec3b>(i,c))[1]) + beta); //modified m.at<vec3b>(i,c)[2] = saturate_cast<uchar>(alpha* (m.at<vec3b>(i,c))[2]) + beta); //modified } } return m; }
Comments
Post a Comment