-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Small inefficiency in seamless clone init #16168
Copy link
Copy link
Closed
Milestone
Description
I have just been reading through the implementation of seamless cloning, and ran across those two bits of code:
Cloning::computeGradientX
opencv/modules/photo/src/seamless_cloning_impl.cpp
Lines 58 to 66 in 4c71dbf
| else if (img.channels() == 1) | |
| { | |
| Mat tmp[3]; | |
| for(int chan = 0 ; chan < 3 ; ++chan) | |
| { | |
| filter2D(img, tmp[chan], CV_32F, kernel); | |
| } | |
| merge(tmp, 3, gx); | |
| } |
Cloning::computeGradientY
opencv/modules/photo/src/seamless_cloning_impl.cpp
Lines 79 to 87 in 4c71dbf
| else if (img.channels() == 1) | |
| { | |
| Mat tmp[3]; | |
| for(int chan = 0 ; chan < 3 ; ++chan) | |
| { | |
| filter2D(img, tmp[chan], CV_32F, kernel); | |
| } | |
| merge(tmp, 3, gy); | |
| } |
It appears to me that the loop calculates the same thing 3x in a row. Wouldn't it make more sense to just run filter2D once, and either merge 3 shallow copies of the result, or outright use mixChannels?
Reactions are currently unavailable