FrancisGOS commited on
Commit
a485c33
2 Parent(s): 40a6098 2cc7aa0
Files changed (2) hide show
  1. app/custom_mmcv/main.py +0 -29
  2. app/routers/image.py +3 -2
app/custom_mmcv/main.py CHANGED
@@ -13,27 +13,6 @@ from .color import Color, color_val
13
  ColorType = Union[Color, str, tuple, int, np.ndarray]
14
 
15
 
16
- def imshow(img: Union[str, np.ndarray], win_name: str = "", wait_time: int = 0):
17
- """Show an image.
18
-
19
- Args:
20
- img (str or ndarray): The image to be displayed.
21
- win_name (str): The window name.
22
- wait_time (int): Value of waitKey param.
23
- """
24
- cv2.imshow(win_name, imread(img))
25
- if wait_time == 0: # prevent from hanging if windows was closed
26
- while True:
27
- ret = cv2.waitKey(1)
28
-
29
- closed = cv2.getWindowProperty(win_name, cv2.WND_PROP_VISIBLE) < 1
30
- # if user closed window or if some key pressed
31
- if closed or ret != -1:
32
- break
33
- else:
34
- ret = cv2.waitKey(wait_time)
35
-
36
-
37
  def imshow_det_bboxes(
38
  img: Union[str, np.ndarray],
39
  bboxes: np.ndarray,
@@ -44,9 +23,6 @@ def imshow_det_bboxes(
44
  text_color: ColorType = "green",
45
  thickness: int = 1,
46
  font_scale: float = 1,
47
- show: bool = True,
48
- win_name: str = "",
49
- wait_time: int = 0,
50
  out_file: Optional[str] = None,
51
  colors: np.ndarray = None,
52
  ):
@@ -65,9 +41,6 @@ def imshow_det_bboxes(
65
  of texts.
66
  thickness (int): Thickness of lines.
67
  font_scale (float): Font scales of texts.
68
- show (bool): Whether to show the image.
69
- win_name (str): The window name.
70
- wait_time (int): Value of waitKey param.
71
  out_file (str or None): The filename to write the image.
72
  colors (array of tuple RGB int): the color of bbox and label of each class
73
 
@@ -110,8 +83,6 @@ def imshow_det_bboxes(
110
  4,
111
  )
112
 
113
- if show:
114
- imshow(img, win_name, wait_time)
115
  if out_file is not None:
116
  imwrite(img, out_file)
117
  return img
 
13
  ColorType = Union[Color, str, tuple, int, np.ndarray]
14
 
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def imshow_det_bboxes(
17
  img: Union[str, np.ndarray],
18
  bboxes: np.ndarray,
 
23
  text_color: ColorType = "green",
24
  thickness: int = 1,
25
  font_scale: float = 1,
 
 
 
26
  out_file: Optional[str] = None,
27
  colors: np.ndarray = None,
28
  ):
 
41
  of texts.
42
  thickness (int): Thickness of lines.
43
  font_scale (float): Font scales of texts.
 
 
 
44
  out_file (str or None): The filename to write the image.
45
  colors (array of tuple RGB int): the color of bbox and label of each class
46
 
 
83
  4,
84
  )
85
 
 
 
86
  if out_file is not None:
87
  imwrite(img, out_file)
88
  return img
app/routers/image.py CHANGED
@@ -6,6 +6,7 @@ from app.constants import classNames, colors
6
  from app import detector
7
  from mmcv import imfrombytes
8
  from app.custom_mmcv.main import imshow_det_bboxes
 
9
 
10
  router = APIRouter(prefix="/image", tags=["Image"])
11
 
@@ -23,7 +24,8 @@ async def handleImageRequest(
23
  return {"bboxes": bboxes.tolist(), "labels": labels.tolist()}
24
 
25
  img = inferenceImage(img, threshold, False)
26
- except:
 
27
  return Response(content="Failed to read image", status_code=400)
28
 
29
  ret, jpeg = cv2.imencode(".jpg", img)
@@ -52,7 +54,6 @@ def inferenceImage(img, threshold: float, isRaw: bool = False):
52
  bboxes=bboxes,
53
  labels=labels,
54
  class_names=classNames,
55
- show=False,
56
  colors=colors,
57
  score_thr=threshold,
58
  )
 
6
  from app import detector
7
  from mmcv import imfrombytes
8
  from app.custom_mmcv.main import imshow_det_bboxes
9
+ from app import logger
10
 
11
  router = APIRouter(prefix="/image", tags=["Image"])
12
 
 
24
  return {"bboxes": bboxes.tolist(), "labels": labels.tolist()}
25
 
26
  img = inferenceImage(img, threshold, False)
27
+ except Exception as e:
28
+ logger.error(e)
29
  return Response(content="Failed to read image", status_code=400)
30
 
31
  ret, jpeg = cv2.imencode(".jpg", img)
 
54
  bboxes=bboxes,
55
  labels=labels,
56
  class_names=classNames,
 
57
  colors=colors,
58
  score_thr=threshold,
59
  )