Question: I am working with Express and mongoose . Don't know why `array.push` is not working . Maybe I am calling it in asynchronous function . 

```
function x(){
    var a = [] ;
    database.auth.distinct('tag',function(err , tagname){
        console.log(tagname); // printing tag names perfectly
        a.push(tagname);

    });
       console.log("a =" ,a); // printing an empty array 
    /*for(var x = 0; x< a.length ; x++){  //so this block is not working .
        database.auth.count({ 'tag' : a[x] },function(err, nish){
            // a[tagname[x]] = nish.length ;

        });*/

   // }

```

Answer: 
You can use [`cv2.rectangle()`](https://docs.opencv.org/3.1.0/d6/d6e/group__imgproc__draw.html#ga07d2f74cadcf8e305e810ce8eed13bc9):

```
cv2.rectangle(img, pt1, pt2, color, thickness, lineType, shift)

Draws a simple, thick, or filled up-right rectangle.

The function rectangle draws a rectangle outline or a filled rectangle
whose two opposite corners are pt1 and pt2.

Parameters
    img   Image.
    pt1   Vertex of the rectangle.
    pt2    Vertex of the rectangle opposite to pt1 .
    color Rectangle color or brightness (grayscale image).
    thickness  Thickness of lines that make up the rectangle. Negative values,
    like CV_FILLED , mean that the function has to draw a filled rectangle.
    lineType  Type of the line. See the line description.
    shift   Number of fractional bits in the point coordinates.

```

I have a PIL Image object and I want to draw rectangle on this image. **I want to use opencv2 and draw rectangle, and then convert back to PIL Image object**. Here is how I do it:

```
# im is a PIL Image object
im_arr = np.asarray(im)
# convert rgb array to opencv's bgr format
im_arr_bgr = cv2.cvtColor(im_arr, cv2.COLOR_RGB2BGR)
# pts1 and pts2 are the upper left and bottom right coordinates of the rectangle
cv2.rectangle(im_arr_bgr, pts1, pts2,
              color=(0, 255, 0), thickness=3)
im_arr = cv2.cvtColor(im_arr_bgr, cv2.COLOR_BGR2RGB)
# convert back to Image object
im = Image.fromarray(im_arr)

```
The code for drawing a rectangle on an image is:

```
cv2.rectangle(image, pt1, pt2, color, thickness)

```

where `pt1` is starting point-->(x,y) and `pt2` is end point-->(x+w,y+h).