c++ - Passing IplImage * to function, original not getting updated -
i having problem passing iplimage* parameters in functions. school project , unfortunately not supposed edit files doing calling filter functions. in main, image brought in command line parameter, re-create of made , passed right filter function, such:
iplimage * floating = cvcreateimage (cvsize (img->width, img->height), ipl_depth_32f, 3); cvconvertscale (img, floating, 1/255., 0); iplimage * filtered; switch (filter.imageformat) { case yuv24: filtered = cvcreateimage (cvsize (floating->width, floating->height), ipl_depth_32f, 3); cvcvtcolor (floating, filtered, cv_bgr2ycrcb); break; case bgr24: filtered = cvcloneimage (floating); break; case gray: filtered = cvcreateimage (cvsize (floating->width, floating->height), ipl_depth_32f, 1); cvcvtcolor (floating, filtered, cv_bgr2gray); break; } cvnamedwindow ("original", cv_window_autosize); cvshowimage ("original", img); filter.imagefilter (filtered, p); if (filter.imageformat == yuv24) { cvcvtcolor (filtered, filtered, cv_ycrcb2bgr); } cvnamedwindow (filtername.c_str(), cv_window_autosize); cvshowimage (filtername.c_str(), filtered); and here code 1 of filters:
void median (iplimage * image, int k){ cout << "image address: " << &image << endl; mat matimage(image); //convert iplimage mat work vector<mat> bgr_channels; //vector hold each channel int i,j,m,n; //row/column indeces int kernelsize = (2*k+1)*(2*k+1); vector<float> vals(kernelsize); //kernelsized vector hold values of image //within kernel centered @ given pixel int vecindex = 0; //then sorted median int chanindex = 0; //index used each channel //add padding business relationship border issues convolution copymakeborder( matimage, matimage, k, k, k, k, border_replicate); //split channes work on individual channels split(matimage, bgr_channels); for(chanindex=0; chanindex < matimage.channels(); chanindex++){ //outer loop scanning entire image for(i=k; i<matimage.rows-k; i++)/*image row index*/{ for(j=k; j<matimage.cols-k; j++)/*image column index*/{ //inner loop scanning image in kernel boundaries vecindex = 0; //reset vecindex @ start of each kernel loop for(m=i-k; m<(i+k+1); m++)/*kernel row index*/{ for(n=j-k; n<(j+k+1); n++)/*kernel column index*/{ vals[vecindex++] = bgr_channels[chanindex].at<float>(m,n); } } insertionsort(vals, 0, vals.size()-1); //insertion sort csci362 text, see references bgr_channels[chanindex].at<float>(i,j) = vals[vals.size()/2]; //new value chosen middle element //of sorted vector } } } merge(bgr_channels, matimage); //merge channels imshow("median: mat", matimage); //left in becuase original doesn't seem modified //when converting mat iplimage image = cvcloneimage(&(iplimage)matimage); //convert backto iplimage desktopmain } the problem is, filtered image shown in main, not reflect actual image. shows original image. when output set mat style image matimage in filter function, shows filtered image. after convert iplimage , set iplimage* input parameter equal the converted, filtered version. changes not reflect image displayed in main function.
this making hard create of other filters such gaussian , sobel, because filters create calls other functions before doing manipulations, , not getting edited info back. there missing in how edit passed iplimage* variable?
thank in advance help!
instead of this:
image = cvcloneimage(&(iplimage)matimage); use this:
cvcopy(&(iplimage)matimage,image); c++ c opencv parameter-passing iplimage
No comments:
Post a Comment