Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Draw a blurring rectangle

Goal – to provide an easy way to specify one or multiple regions on an image for mosaic effect via mouse operations.

Steps (1) Load an image from your project local drive, say “test.jpg” and display it by OpenCV.

(The example image )

image description

(2) For each region, user just needs two left-clicks to define it. The positions where the mouse clicks occur are considered as the two corners along a diagonal line of a rectangular,

image description

(3) Pixels inside the rectangular region that defined by the user should be blurred with Mosaic effect. The level of blur depends on the user specified value. For example, you can use an integer variable to store it: int blur_degree = 5 Here “blur_degree” defines the length of each Mosaic unit square, By default it is 5 pixels in length. So the bigger of the “blur_degree”, the more blur of the selected region

image description

(4) User can increase the blur level by hitting the keyboard key “i” or “I” and decrease the blur level by hitting the keyboard key “d” or “D”. The way of increasing or decreasing blur level follows the rule below:

a) Increasing Case: when “blur_degree” is less than 5, it increases by 1 each time when the key “i” or “I” is hit; when “blur_degree” is equal to or greater than 5, it increases by 5 each time when the key “i” or “I” is hit;

b) Decreasing Case: when the “blur_degree” is equal to or less than 5 but greater than 1, it decreases by 1 each time when the key “d” or “D” is hit; when “blur_degree” is greater than 5, it decreases by 5 each time when the key “d” or “D” is hit;

(5) During editing, user can remove the blur effect at any time by hitting the key “r” or “R”, just in case the region is not selected properly.

(6) After the user finishes editing, the result image should be saved to a local drive with whatever filename by hitting the “s“ or “S” key.

Thanks a lot