grayscale image on webcam using opencv (cant show full image) -


i'm trying create grayscale operation via webcam using opencv (cvcapture). here code

void h_grayscale( unsigned char* h_in, unsigned char* h_out) { for(int i=0;i<height;i++){     for(int j=0;j<width;j++){        int index = h_in[i*widthstep + j*channels];        int gray = 0.3*(index)+0.6*(index+1)+0.1*(index+2);        h_out[i*widthstepoutput+j]=gray;    } }  } 

main code

int main(int argc, char** argv) { int c;   iplimage *image_input;  cvcapture* capture = cvcapturefromcam(1);    while(1) {     image_input=cvqueryframe(capture);     iplimage* image_output = cvcreateimage(cvgetsize(image_input),ipl_depth_8u,image_input->nchannels);      unsigned char *h_out = (unsigned char*)image_output->imagedata;     unsigned char *h_in =  (unsigned char*)image_input->imagedata;      width     = image_input->width;     height    = image_input->height;     channels  = image_input->nchannels;     widthstep = image_input->widthstep;     widthstepoutput = image_input->widthstep;     h_grayscale ( h_in , h_out ) ;     //negatif_parallel(h_in, h_out, width, height, widthstep, channels);      cvshowimage("original", image_input);     cvshowimage("cpu", image_output);      c=cvwaitkey(10);     if(c == 27)         break;     } return 0; } 

but when executed images appear one-third of overall picture. not know part wrong. here result: result

please mee t_t..thx before :))

your output image 3 channel image, thats's why have 1/3 of image.

try create with:

iplimage* image_output = cvcreateimage(cvgetsize(image_input),ipl_depth_8u,1);  

this code works (try find differnces):

int height=0; int width=0; int channels=0; int widthstep=0; int widthstepoutput=0; void h_grayscale( unsigned char* h_in, unsigned char* h_out); int main(int argc, char** argv) {     int c;       iplimage *image_input;      cvcapture* capture = cvcapturefromcam(0);        while(1)     {         image_input=cvqueryframe(capture);         iplimage* image_output = cvcreateimage(cvsize(image_input->width,image_input->height),ipl_depth_8u,1);          unsigned char *h_out = (unsigned char*)image_output->imagedata;         unsigned char *h_in =  (unsigned char*)image_input->imagedata;          width     = image_input->width;         height    = image_input->height;         channels  = image_input->nchannels;         widthstep = image_input->widthstep;         widthstepoutput = image_output->widthstep;          h_grayscale ( h_in , h_out ) ;         //negatif_parallel(h_in, h_out, width, height, widthstep, channels);          cvshowimage("original", image_input);         cvshowimage("cpu", image_output);          c=cvwaitkey(10);         if(c == 27)             break;      }     return 0; }  void h_grayscale( unsigned char* h_in, unsigned char* h_out) {     for(int i=0;i<height;i++){         for(int j=0;j<width;j++){             int index = h_in[i*widthstep + j*channels];             int gray = 0.3*(index)+0.6*(index+1)+0.1*(index+2);             h_out[i*widthstepoutput+j]=gray;         }     } } 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -