arcjetCV.segmentation.contour.contour module

arcjetCV.segmentation.contour.contour.contoursAutoHSV(orig, log=None, flags={'UNDEREXPOSED': False})[source]

Find contours using default union of multiple HSV ranges. Uses the BGR-HSV transformation to increase contrast.

Parameters:
  • orig – opencv 8bit BGR image

  • flags – dictionary with flags

  • log – log object

Returns:

model contour, shock contour, flags

arcjetCV.segmentation.contour.contour.contoursCNN(orig, model, log=None)[source]

Find contours using HSV ranges image. Uses the BGR-HSV transformation to increase contrast.

Parameters:
  • orig – opencv 8bit BGR image

  • model – compiled CNN model

Returns:

model contour, shock contour

arcjetCV.segmentation.contour.contour.contoursGRAY(orig, thresh=150, log=None)[source]

Detects contours in potentially overexposed images using a global grayscale threshold.

This function first converts the input image to grayscale and then applies a binary threshold to isolate potentially overexposed regions. The function then detects and returns the largest contour found, if any, based on the area. In the event no contours are detected, the function logs the failure if a logging object is provided.

Parameters: :param orig: An OpenCV BGR image (8-bit depth). This is typically an image that may contain

overexposed regions where contours need to be identified.

Parameters:
  • thresh – Integer value to apply as a threshold for binary segmentation. Defaults to 150. Regions with grayscale values greater than this threshold will be considered as potential contour areas.

  • log – An optional logging object with a write method to capture any logging messages. Especially useful to track when contour detection fails. Default is None.

Returns: :return: A tuple containing:

  • contour_dict: Dictionary with keys “MODEL” and “SHOCK”. “MODEL” will contain the largest detected contour or None if not found. “SHOCK” is currently always set to None.

  • flags: Dictionary indicating success or failure of contour detection. Contains keys “SHOCK_CONTOUR_FAILED” (always set to True) and “MODEL_CONTOUR_FAILED” (set to True if contour detection fails).

Example:

img = cv.imread(‘overexposed_image.jpg’) contours, flags = contoursGRAY(img) if not flags[‘MODEL_CONTOUR_FAILED’]:

cv.drawContours(img, [contours[‘MODEL’]], -1, (0, 255, 0), 2) cv.imshow(‘Detected Contour’, img) cv.waitKey(0)

arcjetCV.segmentation.contour.contour.contoursHSV(orig, log=None, minHSVModel=(0, 0, 150), maxHSVModel=(181, 125, 256), minHSVShock=(125, 78, 115), maxHSVShock=(145, 190, 230))[source]

Find contours using HSV ranges image. Uses the BGR-HSV transformation to increase contrast.

Parameters:
  • orig – opencv 8bit BGR image

  • minHSVModel – minimum tuple for HSV range

  • maxHSVModel – maximum tuple for HSV range

  • minHSVShock – minimum tuple for HSV range

  • maxHSVShock – maximum tuple for HSV range

Returns:

model contour, shock contour

arcjetCV.segmentation.contour.contour.filter_hsv_ranges(hsv: <Mock name='mock.ndarray' id='140551862173824'>, ranges) <Mock name='mock.ndarray' id='140551862173824'>[source]

Filter an HSV image using multiple hue-saturation-value (HSV) ranges and return the combined mask.

The function applies multiple HSV range filters to the input image and combines the results using a bitwise OR operation to create a single mask that captures all the specified ranges.

Args:

hsv (np.ndarray): Input HSV image. ranges (tuple of two lists of lists): A tuple containing two lists.

The first list contains the lower bounds of multiple HSV ranges, and the second list contains the upper bounds for those same ranges. Each bound in the lists is itself a list or tuple of three values (H, S, V). The number of range pairs (lower and upper bounds) can vary.

Returns:
np.ndarray: A combined binary mask where pixels falling within any of the provided

HSV ranges are set to 255 (white), and all others are set to 0 (black).

Examples:
>>> filter_hsv_ranges(hsv_image, ([ [0, 50, 50], [20, 100, 100] ], [ [10, 255, 255], [30, 150, 150] ]))
# Returns a mask where only the pixels in two ranges are white:
# 1) 0<H<10, 50<S<255, 50<V<255
# 2) 20<H<30, 100<S<150, 100<V<150
arcjetCV.segmentation.contour.contour.getEdgeFromContour(c, flow_direction, offset=None)[source]

Find the leading edge of a contour for a given flow direction

Parameters:
  • c – opencv contour, shape(n,1,n)

  • flow_direction – ‘left’, ‘right’, ‘up’, or ‘down’

Returns:

frontedge, contour of front edge

arcjetCV.segmentation.contour.contour.getPoints(c, flow_direction='right', r=[-0.95, -0.5, 0, 0.5, 0.95], prefix='MODEL')[source]

Given an OpenCV contour, this function returns interpolated points at specified relative vertical positions to the center of the contour.

Assumptions: 1. Only the leading edge is passed into the function (not a closed contour). 2. The contour is dense, meaning every vertical pixel is occupied.

Parameters: :param c: An OpenCV contour of shape (n, 1, n). :param flow_direction (str): Indicates the direction of the flow. Acceptable values

are “right”, “left”, “up”, or “down”. Default is “right”.

Parameters:
  • (list) (r) – A list of interpolation points relative to the contour’s radius. Default is [-0.95, -0.50, 0, 0.50, 0.95].

  • (str) (prefix) – A prefix string for keys in the output dictionary. Default is “MODEL”.

Returns: :return: A dictionary containing:

  • [prefix]+’_R’: List of relative interpolation points.

  • [prefix]+’_YCENTER’: Y-coordinate of the center of the contour.

  • [prefix]+’_YLOW’: Minimum Y-coordinate of the contour.

  • [prefix]+’_CROP_YMAX’: Maximum Y-coordinate of the contour.

  • [prefix]+’_RADIUS’: Radius (half of the height) of the contour.

  • [prefix]+’_INTERP_XPOS’: Interpolated X-coordinates corresponding to each point in ‘r’.