We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
imshow_bboxes does not show bboxes if img is incontiguous 
As [DKDKDDK](https://stackoverflow.com/questions/57586449/why-cv2-rectangle-sometimes-return-np-ndarray-while-sometimes-cv2-umat) asked, cv2.rectangle seems unable to draw inplacely on incontiguous arrays. When calling `mmcv.imshow_bboxes` or `mmcv.imshow_det_bboxes`, the contiguousness of argument `img` is consistent with what the user passed in. Would it be convenient to add `img = np.ascontiguousarray(img)` inside `mmcv.imshow_bboxes` and `mmcv.imshow_det_bboxes`?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mmcv/visualization/image.py`
Content:
```
1 # Copyright (c) Open-MMLab. All rights reserved.
2 import cv2
3 import numpy as np
4 
5 from mmcv.image import imread, imwrite
6 from .color import color_val
7 
8 
9 def imshow(img, win_name='', wait_time=0):
10     """Show an image.
11 
12     Args:
13         img (str or ndarray): The image to be displayed.
14         win_name (str): The window name.
15         wait_time (int): Value of waitKey param.
16     """
17     cv2.imshow(win_name, imread(img))
18     if wait_time == 0:  # prevent from hangning if windows was closed
19         while True:
20             ret = cv2.waitKey(1)
21 
22             closed = cv2.getWindowProperty(win_name, cv2.WND_PROP_VISIBLE) < 1
23             # if user closed window or if some key pressed
24             if closed or ret != -1:
25                 break
26     else:
27         ret = cv2.waitKey(wait_time)
28 
29 
30 def imshow_bboxes(img,
31                   bboxes,
32                   colors='green',
33                   top_k=-1,
34                   thickness=1,
35                   show=True,
36                   win_name='',
37                   wait_time=0,
38                   out_file=None):
39     """Draw bboxes on an image.
40 
41     Args:
42         img (str or ndarray): The image to be displayed.
43         bboxes (list or ndarray): A list of ndarray of shape (k, 4).
44         colors (list[str or tuple or Color]): A list of colors.
45         top_k (int): Plot the first k bboxes only if set positive.
46         thickness (int): Thickness of lines.
47         show (bool): Whether to show the image.
48         win_name (str): The window name.
49         wait_time (int): Value of waitKey param.
50         out_file (str, optional): The filename to write the image.
51 
52     Returns:
53         ndarray: The image with bboxes drawn on it.
54     """
55     img = imread(img)
56 
57     if isinstance(bboxes, np.ndarray):
58         bboxes = [bboxes]
59     if not isinstance(colors, list):
60         colors = [colors for _ in range(len(bboxes))]
61     colors = [color_val(c) for c in colors]
62     assert len(bboxes) == len(colors)
63 
64     for i, _bboxes in enumerate(bboxes):
65         _bboxes = _bboxes.astype(np.int32)
66         if top_k <= 0:
67             _top_k = _bboxes.shape[0]
68         else:
69             _top_k = min(top_k, _bboxes.shape[0])
70         for j in range(_top_k):
71             left_top = (_bboxes[j, 0], _bboxes[j, 1])
72             right_bottom = (_bboxes[j, 2], _bboxes[j, 3])
73             cv2.rectangle(
74                 img, left_top, right_bottom, colors[i], thickness=thickness)
75 
76     if show:
77         imshow(img, win_name, wait_time)
78     if out_file is not None:
79         imwrite(img, out_file)
80     return img
81 
82 
83 def imshow_det_bboxes(img,
84                       bboxes,
85                       labels,
86                       class_names=None,
87                       score_thr=0,
88                       bbox_color='green',
89                       text_color='green',
90                       thickness=1,
91                       font_scale=0.5,
92                       show=True,
93                       win_name='',
94                       wait_time=0,
95                       out_file=None):
96     """Draw bboxes and class labels (with scores) on an image.
97 
98     Args:
99         img (str or ndarray): The image to be displayed.
100         bboxes (ndarray): Bounding boxes (with scores), shaped (n, 4) or
101             (n, 5).
102         labels (ndarray): Labels of bboxes.
103         class_names (list[str]): Names of each classes.
104         score_thr (float): Minimum score of bboxes to be shown.
105         bbox_color (str or tuple or :obj:`Color`): Color of bbox lines.
106         text_color (str or tuple or :obj:`Color`): Color of texts.
107         thickness (int): Thickness of lines.
108         font_scale (float): Font scales of texts.
109         show (bool): Whether to show the image.
110         win_name (str): The window name.
111         wait_time (int): Value of waitKey param.
112         out_file (str or None): The filename to write the image.
113 
114     Returns:
115         ndarray: The image with bboxes drawn on it.
116     """
117     assert bboxes.ndim == 2
118     assert labels.ndim == 1
119     assert bboxes.shape[0] == labels.shape[0]
120     assert bboxes.shape[1] == 4 or bboxes.shape[1] == 5
121     img = imread(img)
122 
123     if score_thr > 0:
124         assert bboxes.shape[1] == 5
125         scores = bboxes[:, -1]
126         inds = scores > score_thr
127         bboxes = bboxes[inds, :]
128         labels = labels[inds]
129 
130     bbox_color = color_val(bbox_color)
131     text_color = color_val(text_color)
132     img = np.ascontiguousarray(img)
133     for bbox, label in zip(bboxes, labels):
134         bbox_int = bbox.astype(np.int32)
135         left_top = (bbox_int[0], bbox_int[1])
136         right_bottom = (bbox_int[2], bbox_int[3])
137         cv2.rectangle(
138             img, left_top, right_bottom, bbox_color, thickness=thickness)
139         label_text = class_names[
140             label] if class_names is not None else f'cls {label}'
141         if len(bbox) > 4:
142             label_text += f'|{bbox[-1]:.02f}'
143         cv2.putText(img, label_text, (bbox_int[0], bbox_int[1] - 2),
144                     cv2.FONT_HERSHEY_COMPLEX, font_scale, text_color)
145 
146     if show:
147         imshow(img, win_name, wait_time)
148     if out_file is not None:
149         imwrite(img, out_file)
150     return img
151
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mmcv/visualization/image.py b/mmcv/visualization/image.py
--- a/mmcv/visualization/image.py
+++ b/mmcv/visualization/image.py
@@ -53,6 +53,7 @@
         ndarray: The image with bboxes drawn on it.
     """
     img = imread(img)
+    img = np.ascontiguousarray(img)
 
     if isinstance(bboxes, np.ndarray):
         bboxes = [bboxes]
@@ -119,6 +120,7 @@
     assert bboxes.shape[0] == labels.shape[0]
     assert bboxes.shape[1] == 4 or bboxes.shape[1] == 5
     img = imread(img)
+    img = np.ascontiguousarray(img)
 
     if score_thr > 0:
         assert bboxes.shape[1] == 5
@@ -129,7 +131,7 @@
 
     bbox_color = color_val(bbox_color)
     text_color = color_val(text_color)
-    img = np.ascontiguousarray(img)
+
     for bbox, label in zip(bboxes, labels):
         bbox_int = bbox.astype(np.int32)
         left_top = (bbox_int[0], bbox_int[1])

{"golden_diff": "diff --git a/mmcv/visualization/image.py b/mmcv/visualization/image.py\n--- a/mmcv/visualization/image.py\n+++ b/mmcv/visualization/image.py\n@@ -53,6 +53,7 @@\n         ndarray: The image with bboxes drawn on it.\n     \"\"\"\n     img = imread(img)\n+    img = np.ascontiguousarray(img)\n \n     if isinstance(bboxes, np.ndarray):\n         bboxes = [bboxes]\n@@ -119,6 +120,7 @@\n     assert bboxes.shape[0] == labels.shape[0]\n     assert bboxes.shape[1] == 4 or bboxes.shape[1] == 5\n     img = imread(img)\n+    img = np.ascontiguousarray(img)\n \n     if score_thr > 0:\n         assert bboxes.shape[1] == 5\n@@ -129,7 +131,7 @@\n \n     bbox_color = color_val(bbox_color)\n     text_color = color_val(text_color)\n-    img = np.ascontiguousarray(img)\n+\n     for bbox, label in zip(bboxes, labels):\n         bbox_int = bbox.astype(np.int32)\n         left_top = (bbox_int[0], bbox_int[1])\n", "issue": "imshow_bboxes does not show bboxes if img is incontiguous \nAs [DKDKDDK](https://stackoverflow.com/questions/57586449/why-cv2-rectangle-sometimes-return-np-ndarray-while-sometimes-cv2-umat) asked, cv2.rectangle seems unable to draw inplacely on incontiguous arrays. When calling `mmcv.imshow_bboxes` or `mmcv.imshow_det_bboxes`, the contiguousness of argument `img` is consistent with what the user passed in. Would it be convenient to add `img = np.ascontiguousarray(img)` inside `mmcv.imshow_bboxes` and `mmcv.imshow_det_bboxes`?\n", "before_files": [{"content": "# Copyright (c) Open-MMLab. All rights reserved.\nimport cv2\nimport numpy as np\n\nfrom mmcv.image import imread, imwrite\nfrom .color import color_val\n\n\ndef imshow(img, win_name='', wait_time=0):\n    \"\"\"Show an image.\n\n    Args:\n        img (str or ndarray): The image to be displayed.\n        win_name (str): The window name.\n        wait_time (int): Value of waitKey param.\n    \"\"\"\n    cv2.imshow(win_name, imread(img))\n    if wait_time == 0:  # prevent from hangning if windows was closed\n        while True:\n            ret = cv2.waitKey(1)\n\n            closed = cv2.getWindowProperty(win_name, cv2.WND_PROP_VISIBLE) < 1\n            # if user closed window or if some key pressed\n            if closed or ret != -1:\n                break\n    else:\n        ret = cv2.waitKey(wait_time)\n\n\ndef imshow_bboxes(img,\n                  bboxes,\n                  colors='green',\n                  top_k=-1,\n                  thickness=1,\n                  show=True,\n                  win_name='',\n                  wait_time=0,\n                  out_file=None):\n    \"\"\"Draw bboxes on an image.\n\n    Args:\n        img (str or ndarray): The image to be displayed.\n        bboxes (list or ndarray): A list of ndarray of shape (k, 4).\n        colors (list[str or tuple or Color]): A list of colors.\n        top_k (int): Plot the first k bboxes only if set positive.\n        thickness (int): Thickness of lines.\n        show (bool): Whether to show the image.\n        win_name (str): The window name.\n        wait_time (int): Value of waitKey param.\n        out_file (str, optional): The filename to write the image.\n\n    Returns:\n        ndarray: The image with bboxes drawn on it.\n    \"\"\"\n    img = imread(img)\n\n    if isinstance(bboxes, np.ndarray):\n        bboxes = [bboxes]\n    if not isinstance(colors, list):\n        colors = [colors for _ in range(len(bboxes))]\n    colors = [color_val(c) for c in colors]\n    assert len(bboxes) == len(colors)\n\n    for i, _bboxes in enumerate(bboxes):\n        _bboxes = _bboxes.astype(np.int32)\n        if top_k <= 0:\n            _top_k = _bboxes.shape[0]\n        else:\n            _top_k = min(top_k, _bboxes.shape[0])\n        for j in range(_top_k):\n            left_top = (_bboxes[j, 0], _bboxes[j, 1])\n            right_bottom = (_bboxes[j, 2], _bboxes[j, 3])\n            cv2.rectangle(\n                img, left_top, right_bottom, colors[i], thickness=thickness)\n\n    if show:\n        imshow(img, win_name, wait_time)\n    if out_file is not None:\n        imwrite(img, out_file)\n    return img\n\n\ndef imshow_det_bboxes(img,\n                      bboxes,\n                      labels,\n                      class_names=None,\n                      score_thr=0,\n                      bbox_color='green',\n                      text_color='green',\n                      thickness=1,\n                      font_scale=0.5,\n                      show=True,\n                      win_name='',\n                      wait_time=0,\n                      out_file=None):\n    \"\"\"Draw bboxes and class labels (with scores) on an image.\n\n    Args:\n        img (str or ndarray): The image to be displayed.\n        bboxes (ndarray): Bounding boxes (with scores), shaped (n, 4) or\n            (n, 5).\n        labels (ndarray): Labels of bboxes.\n        class_names (list[str]): Names of each classes.\n        score_thr (float): Minimum score of bboxes to be shown.\n        bbox_color (str or tuple or :obj:`Color`): Color of bbox lines.\n        text_color (str or tuple or :obj:`Color`): Color of texts.\n        thickness (int): Thickness of lines.\n        font_scale (float): Font scales of texts.\n        show (bool): Whether to show the image.\n        win_name (str): The window name.\n        wait_time (int): Value of waitKey param.\n        out_file (str or None): The filename to write the image.\n\n    Returns:\n        ndarray: The image with bboxes drawn on it.\n    \"\"\"\n    assert bboxes.ndim == 2\n    assert labels.ndim == 1\n    assert bboxes.shape[0] == labels.shape[0]\n    assert bboxes.shape[1] == 4 or bboxes.shape[1] == 5\n    img = imread(img)\n\n    if score_thr > 0:\n        assert bboxes.shape[1] == 5\n        scores = bboxes[:, -1]\n        inds = scores > score_thr\n        bboxes = bboxes[inds, :]\n        labels = labels[inds]\n\n    bbox_color = color_val(bbox_color)\n    text_color = color_val(text_color)\n    img = np.ascontiguousarray(img)\n    for bbox, label in zip(bboxes, labels):\n        bbox_int = bbox.astype(np.int32)\n        left_top = (bbox_int[0], bbox_int[1])\n        right_bottom = (bbox_int[2], bbox_int[3])\n        cv2.rectangle(\n            img, left_top, right_bottom, bbox_color, thickness=thickness)\n        label_text = class_names[\n            label] if class_names is not None else f'cls {label}'\n        if len(bbox) > 4:\n            label_text += f'|{bbox[-1]:.02f}'\n        cv2.putText(img, label_text, (bbox_int[0], bbox_int[1] - 2),\n                    cv2.FONT_HERSHEY_COMPLEX, font_scale, text_color)\n\n    if show:\n        imshow(img, win_name, wait_time)\n    if out_file is not None:\n        imwrite(img, out_file)\n    return img\n", "path": "mmcv/visualization/image.py"}], "after_files": [{"content": "# Copyright (c) Open-MMLab. All rights reserved.\nimport cv2\nimport numpy as np\n\nfrom mmcv.image import imread, imwrite\nfrom .color import color_val\n\n\ndef imshow(img, win_name='', wait_time=0):\n    \"\"\"Show an image.\n\n    Args:\n        img (str or ndarray): The image to be displayed.\n        win_name (str): The window name.\n        wait_time (int): Value of waitKey param.\n    \"\"\"\n    cv2.imshow(win_name, imread(img))\n    if wait_time == 0:  # prevent from hangning if windows was closed\n        while True:\n            ret = cv2.waitKey(1)\n\n            closed = cv2.getWindowProperty(win_name, cv2.WND_PROP_VISIBLE) < 1\n            # if user closed window or if some key pressed\n            if closed or ret != -1:\n                break\n    else:\n        ret = cv2.waitKey(wait_time)\n\n\ndef imshow_bboxes(img,\n                  bboxes,\n                  colors='green',\n                  top_k=-1,\n                  thickness=1,\n                  show=True,\n                  win_name='',\n                  wait_time=0,\n                  out_file=None):\n    \"\"\"Draw bboxes on an image.\n\n    Args:\n        img (str or ndarray): The image to be displayed.\n        bboxes (list or ndarray): A list of ndarray of shape (k, 4).\n        colors (list[str or tuple or Color]): A list of colors.\n        top_k (int): Plot the first k bboxes only if set positive.\n        thickness (int): Thickness of lines.\n        show (bool): Whether to show the image.\n        win_name (str): The window name.\n        wait_time (int): Value of waitKey param.\n        out_file (str, optional): The filename to write the image.\n\n    Returns:\n        ndarray: The image with bboxes drawn on it.\n    \"\"\"\n    img = imread(img)\n    img = np.ascontiguousarray(img)\n\n    if isinstance(bboxes, np.ndarray):\n        bboxes = [bboxes]\n    if not isinstance(colors, list):\n        colors = [colors for _ in range(len(bboxes))]\n    colors = [color_val(c) for c in colors]\n    assert len(bboxes) == len(colors)\n\n    for i, _bboxes in enumerate(bboxes):\n        _bboxes = _bboxes.astype(np.int32)\n        if top_k <= 0:\n            _top_k = _bboxes.shape[0]\n        else:\n            _top_k = min(top_k, _bboxes.shape[0])\n        for j in range(_top_k):\n            left_top = (_bboxes[j, 0], _bboxes[j, 1])\n            right_bottom = (_bboxes[j, 2], _bboxes[j, 3])\n            cv2.rectangle(\n                img, left_top, right_bottom, colors[i], thickness=thickness)\n\n    if show:\n        imshow(img, win_name, wait_time)\n    if out_file is not None:\n        imwrite(img, out_file)\n    return img\n\n\ndef imshow_det_bboxes(img,\n                      bboxes,\n                      labels,\n                      class_names=None,\n                      score_thr=0,\n                      bbox_color='green',\n                      text_color='green',\n                      thickness=1,\n                      font_scale=0.5,\n                      show=True,\n                      win_name='',\n                      wait_time=0,\n                      out_file=None):\n    \"\"\"Draw bboxes and class labels (with scores) on an image.\n\n    Args:\n        img (str or ndarray): The image to be displayed.\n        bboxes (ndarray): Bounding boxes (with scores), shaped (n, 4) or\n            (n, 5).\n        labels (ndarray): Labels of bboxes.\n        class_names (list[str]): Names of each classes.\n        score_thr (float): Minimum score of bboxes to be shown.\n        bbox_color (str or tuple or :obj:`Color`): Color of bbox lines.\n        text_color (str or tuple or :obj:`Color`): Color of texts.\n        thickness (int): Thickness of lines.\n        font_scale (float): Font scales of texts.\n        show (bool): Whether to show the image.\n        win_name (str): The window name.\n        wait_time (int): Value of waitKey param.\n        out_file (str or None): The filename to write the image.\n\n    Returns:\n        ndarray: The image with bboxes drawn on it.\n    \"\"\"\n    assert bboxes.ndim == 2\n    assert labels.ndim == 1\n    assert bboxes.shape[0] == labels.shape[0]\n    assert bboxes.shape[1] == 4 or bboxes.shape[1] == 5\n    img = imread(img)\n    img = np.ascontiguousarray(img)\n\n    if score_thr > 0:\n        assert bboxes.shape[1] == 5\n        scores = bboxes[:, -1]\n        inds = scores > score_thr\n        bboxes = bboxes[inds, :]\n        labels = labels[inds]\n\n    bbox_color = color_val(bbox_color)\n    text_color = color_val(text_color)\n\n    for bbox, label in zip(bboxes, labels):\n        bbox_int = bbox.astype(np.int32)\n        left_top = (bbox_int[0], bbox_int[1])\n        right_bottom = (bbox_int[2], bbox_int[3])\n        cv2.rectangle(\n            img, left_top, right_bottom, bbox_color, thickness=thickness)\n        label_text = class_names[\n            label] if class_names is not None else f'cls {label}'\n        if len(bbox) > 4:\n            label_text += f'|{bbox[-1]:.02f}'\n        cv2.putText(img, label_text, (bbox_int[0], bbox_int[1] - 2),\n                    cv2.FONT_HERSHEY_COMPLEX, font_scale, text_color)\n\n    if show:\n        imshow(img, win_name, wait_time)\n    if out_file is not None:\n        imwrite(img, out_file)\n    return img\n", "path": "mmcv/visualization/image.py"}]}