Ask Your Question
1

improving functionality of imread

asked 2015-06-24 19:13:44 -0500

updated 2017-08-15 11:18:31 -0500

hi all, i want to share my way to use libjpeg loading options. here my addition to source https://github.com/Itseez/opencv/pull...

by this change i can set "scale_denom" parameter and load jpeg images scaled 1/2 - 1/4 - 1/8

also i wonder if it worth to merge to opencv library after revised by opencv gurus here. any comment is welcome

edit retag flag offensive close merge delete

Comments

i see 2 problems with that approach:

  • (major:) a global variable is used to store the scale factor. now, you can never be sure, in what state it is, also, which other part of the codebase has tried to set it before, so you will have to set it every time you try to imread() something. (you might not even know, what's in the filename)

  • (minor:) your cvSetJpegScale() function is hidden in the deprecated c-api. [in my case, i mostly try to avoid including any of those headers]

berak gravatar imageberak ( 2015-06-25 03:01:18 -0500 )edit

@berak thank you for your valuable critique. i changed something. your comments are very welcome

sturkmen gravatar imagesturkmen ( 2015-06-25 04:34:44 -0500 )edit

yea, i've seen, that you're trying to move it into an additional param for imread()

but this again has the drawback, that the interfaces will have to change, which breaks binary compatibility (which does not go well with the opencv devs)

also, the param is only valid for jpg images

(again, your effort there is highly appreciated, please don't take this all too negative !!)

berak gravatar imageberak ( 2015-06-25 04:48:57 -0500 )edit

@berak did you delete your last comment. i saw it but did not read

sturkmen gravatar imagesturkmen ( 2015-06-27 10:31:03 -0500 )edit
1

well, yes, - temporarily(sorry for confusion) ;) using the imread flags for this seems to be the best idea so far, imho.

(then i was not sure, if the size/allocation would work, but atm, it seems so.)

do you think, there's a way to get rid of the global var and the setter function ?

berak gravatar imageberak ( 2015-06-27 10:38:39 -0500 )edit

@berak it is easy to get rid of the global var and the setter function, then BaseImageDecoder class need a new method to set scale_denom value.

sturkmen gravatar imagesturkmen ( 2015-06-27 11:12:58 -0500 )edit

@StevenPuttemans Can i get your opinion

sturkmen gravatar imagesturkmen ( 2015-06-29 08:01:42 -0500 )edit
1

@sturkmen, I think @berak somewhat pointed all the critical problems out. But maybe adding an overload function on the imread operation is a better way? This ensures that binary compatibility is not broken.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-06-29 08:25:40 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-07-13 09:53:47 -0500

updated 2015-11-16 01:42:30 -0500

new feature added to cv::imread as documented

example usage:

cv::Mat img = cv::imread( "lena.jpg", IMREAD_REDUCED_COLOR_2 ) // loads image reduced 1/2
cv::Mat img = cv::imread( "lena.jpg", IMREAD_REDUCED_GRAYSCALE_8 ) // loads img reduced 1/8 grayscale
edit flag offensive delete link more

Comments

"Can you squash all the commits into one?" - hehe, if you find this a daunting task, you're not the only one ..

berak gravatar imageberak ( 2015-07-13 11:04:52 -0500 )edit
  • if you got 26 commits to squash, the command is: git rebase -i HEAD~26
  • this will put you into vi (oh, shucks, yes, that infamous editor). you'll see a list of commits like:

    pick 0a2a522 com_1

    pick 087f4cb com_2

    pick 05724ed com_3

  • change all but the 1st 'pick'(or the one you want to keep) to 'stash' (or 's'). . you probably need the 'insert' key to toggle insert mode

  • press 'escape' to toggle edit/command mode

  • type a ':' (cursor should go down to bottom line) and a 'w' (for write)
  • again type ':' 'q' (for quit)
  • this was only the 1st vi run, it will be followed by a second, where you're supposed to select/comment out/change the final commit message. comment out('#') anything unneeded, until left with a single line (in yellow)

  • [escape], ':w' , ':q'

;

berak gravatar imageberak ( 2015-07-13 11:25:02 -0500 )edit

any tips for squash all ? :)

sturkmen gravatar imagesturkmen ( 2015-07-13 11:25:38 -0500 )edit
1

@berak you are very kind. you wrote the answer before my question.thank you!!

sturkmen gravatar imagesturkmen ( 2015-07-13 11:27:13 -0500 )edit
1

this is probably the most painful (and annoying) thing i had to learn, when trying to contribute ;)

berak gravatar imageberak ( 2015-07-13 11:33:22 -0500 )edit

@berak i did something but i don't know i am on the rigth way or not. on my fork like https://github.com/sturkmen72/opencv/... but how to update https://github.com/Itseez/opencv/pull...

sturkmen gravatar imagesturkmen ( 2015-07-18 07:36:26 -0500 )edit

ah, so that's a new branch now: "imread_reduced" , while the old pr was "patch-1" ?

you could try to overwrite the old "patch-1" branch with your new content (it will still be named "patch-1":

git checkout imread_reduced
git push -f origin patch-1

(push -f for "forced")

alternatively, you could just close the "patch-1" pr, and make a pull-request for "imread_reduced" (and maybe make a comment)

anyway, cool thing, you're close to getting it in ;)

berak gravatar imageberak ( 2015-07-18 07:47:11 -0500 )edit

@berak thank you

sturkmen gravatar imagesturkmen ( 2015-07-18 07:49:14 -0500 )edit
1

we have to thank you ;)

berak gravatar imageberak ( 2015-07-18 07:51:42 -0500 )edit

i am trying to improve imread_reduced. my goal is by this change, to compute scale_denom value in load process. to explain it lets look example usage:

int onLoad( int width, int height )
{
    int scale = 1;
    if( width > 320 )
        scale =  width / 320;

    return scale;
}

int main( int argc, char** argv )
{
    Mat jpegimage = imread_reduced("fruits.jpg", IMREAD_COLOR, 0 , onLoad ); // onLoad is new ! by this way we can compute scale_denom inside process.
    imshow("jpegimage",jpegimage);
    waitKey();
    return 0;
}

you can see implementing code here . @berak what is your opinion about it.

sturkmen gravatar imagesturkmen ( 2015-08-30 12:45:01 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2015-06-24 19:13:44 -0500

Seen: 345 times

Last updated: Nov 16 '15