/*Pixel Access*/#include<iostream>#include<cv.h>#include<opencv2/core/core.hpp>#include<opencv2/highgui/highgui.hpp>using namespacestd;using namespaceCV; intMainintargcint*argv[]) {Mat image= Imread ("lena.bmp"); Mat OUT1=Image.clone (); LongN_rows =out1.rows; LongN_cols = Out1.cols *out1.channels (); /** Line Pointer*/Uchar*p; for(LongI=0; i<n_rows; i++) {p= out1.ptr<uchar>(i); for(Longj=0; j<n_cols; J + +) {P[j]=255-P[j]; } } /** Element Pointers*/Mat Out2; Out2.create (Image.size (), Image.type ()); //Reserve size and type but alloc new spacen_rows=out2.rows; N_cols= Out2.cols *out2.channels (); P=Out2.data; Doublec =0.5; Doubleb = -; for(LongI=0; i<n_rows*n_cols; i++) { * (p+i) = (Uchar) (255*0.5* ((Double) (Image.data[i])/255) +b); } /** Display*/Imshow ("Src_image", image); Imshow ("Reverse_image", OUT1); Imshow ("Mici_image", OUT2); Waitkey (6000); return 0; }
Opencv2 Learning--pixel manipulation