0

I'm attempting to narrow a screenshot of an app to a specific section of the UI for later processing by Tesseract; in particular, the X Battle ratings located in the lower half of the image.

The test image to process, see the X Battle data in the lower half of the image, above where it says "Top Weapon Wielders".

I did a little bit of research, and saw that color segmentation might be the most practical choice for me. However, the following code, when run, produces a completely black mask:

    // step 1: read the image into a cv::Mat
    cv::Mat source_image = cv::imread("test_data/xrec/ocr_splatnet3/Screenshot_20251021_074323_Nintendo_Switch_App.jpg");

    // step 2: convert to hsv
    cv::Mat hsv;
    cv::cvtColor(source_image, hsv, cv::COLOR_BGR2HSV);
    
    // step 3, make a color mask
    cv::Mat mask;
    cv::Scalar lower_bound(220, 24, 8);
    cv::Scalar upper_bound(224, 34, 18);
    cv::inRange(hsv, lower_bound, upper_bound, mask);
    
    cv::imshow("mask", mask);
    cv::waitKey();
    cv::destroyAllWindows();

    // Tesseract code follows...

Is the range of the upper & lower bound too tight? Or am I just missing some step completely?

9
  • Your comment says make a color mask but you said earlier you wanted to take the lower half of the image. The X battle ratings contain some black and white so you can't extract it with a mask color because it's all the color range. Tell me precisely what region of the image you want to extract please Commented Dec 2 at 7:52
  • in opencv, H is in range [0, 180]. Set your range accordingly Commented Dec 2 at 8:35
  • @VTKEnthusiast I'm interested in the lower UI section where each game mode (Splat Zones, Tower Control, etc.) is listed by the weapon used rating. If an mask isn't the right approach, what might be a better solution? Commented Dec 3 at 3:34
  • I might be missing something, is there any reason why you use this : COLOR_BGR2HSV ? Otherwise, if you want to extract a part of an image, especially a rectangle, it's really easy considering the opencv matrix is just a 2D array (numpy array to be precise) of pixels. See this answer : stackoverflow.com/a/15589825/31966979. Or maybe you are trying to extract the text? Commented Dec 3 at 7:15
  • is the ROI is always in the same place? Commented Dec 3 at 9:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.