def _do_ncs_infer(self, operand, img_label=None):
        """Detect and classify digits. If you provide an img_label the cropped digit image will be written to file."""
        # Get a list of rectangles for objects detected in this operand's box
        op_img = self._canvas[operand.top: operand.bottom, operand.left: operand.right]
        gray_img = cv2.cvtColor(op_img, cv2.COLOR_BGR2GRAY)
        _, binary_img = cv2.threshold(gray_img, 127, 255, cv2.THRESH_BINARY_INV)
        contours, hierarchy = cv2.findContours(binary_img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
        digits = [cv2.boundingRect(contour) for contour in contours]

        if len(digits) > 0:
            x, y, w, h = digits[0]
            digit_img = self._canvas[operand.top + y: operand.top + y + h,
                                     operand.left + x: operand.left + x + w]

            # Write the cropped image to file if a label was provided
            if img_label:
                cv2.imwrite(img_label + ".png", digit_img)

            # Classify the digit and return the most probable result
            value, probability = self._net_processor.do_async_inference(digit_img)[0]
            print("value: " + str(value) + " probability: " + str(probability))
            return value, probability
        else:
            return None, None
Detect and classify digits. If you provide an img_label the cropped digit image will be written to file.
apps/mnist_calc/mnist_calc.py