Ask Your Question

John Sami's profile - activity

2016-01-01 11:56:36 -0500 received badge  Student (source)
2015-09-18 10:39:35 -0500 asked a question How I draw a rectangle by mosaic effect ?

This is my code

      #include <opencv2/core/core.hpp>
      #include <opencv2/highgui/highgui.hpp>

      using namespace std;
      using namespace cv;

      Mat image;
      char click;
      Point p1;
      Point p2;
      static void onMouse(int event, int x, int y, int, void*)
      {

switch (event)
{
case CV_EVENT_LBUTTONDOWN:
        if (click == 0){ // first click  top left
    click = 1;
    printf("%d %d", x, y);

    }
    else {          // second click  bottom right
    click = 2;
    printf("%d %d", x, y);
    }

    break;
case CV_EVENT_LBUTTONUP:
    break;
  }


      }

      void blurImage() {
      // compute the block



  int Num_cols = (p2.x - p1.x) / block;


      int Num_row = (p1.x - p2.x) / block;


for (int i = 0; i < Num_row; i++)
{
    for(int j = 0; j < Num_cols; j++)
{
    int  x1 = p1.x + j * block;
    int  y1 = p1.y + j * block;
    int avg = sum / block*block;


      // assign each pixel value by the block value



      } 
   }
      int main(void)
      {
image = imread("C:/Users/faho0odywbas/Desktop/test.jpg");

namedWindow("Demo");
setMouseCallback("Demo", onMouse);

imshow("Demo", image);
waitKey(0);

return 0;
      }

I want to draw a rectangle that's blur every thing inside it by mosaic effect, so my question is how to compute the block and assign each pixel value by the block value which are missing on my code

So the rectangle will be like this image description

2015-09-18 10:29:36 -0500 commented question Draw a blurring rectangle

This is my code :

Mat image; char click; Point p1; Point p2; static void onMouse(int event, int x, int y, int, void*) {

switch (event)
{
case CV_EVENT_LBUTTONDOWN:
        if (click == 0){ // first click  top left
    click = 1;
    printf("%d %d", x, y);

    }
    else {          // second click  bottom right
    click = 2;
    printf("%d %d", x, y);
    }

    break;
case CV_EVENT_LBUTTONUP:
    break;
}

}

void blurImage() { // compute the block

int Num_cols = (p2.x - p1.x) / block;
int Num_row = (p1.x - p2.x) / block;

for (int i = 0; i < Num_row; i++)
{
for(int j = 0; j < Num_cols; j++)
{
    int  x1 = p1.x + j * block;
    int  y1 = p1.y + j * block;
    int avg = sum / block*block;

// assign each pixel value by the block value }

How can I compute the block and assign each pixel ?

2015-09-18 09:55:23 -0500 commented answer Draw a blurring rectangle

Thanks a lot for your help, but I need a solve for number (3) because I need draw a blur rectangle not a normal rectangle , thanks again

2015-09-17 17:27:52 -0500 asked a question 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