Analyze an image in specific area and determine if it's red using Opencv Python

I'm using Opencv python in raspberry pi, to analize a heatmap, i'm looking for color red, which represents the highest temperature, i need to detect if in an specific area exist red color, in case it does i can use this information to activate a condition, i'm using a heatmap like this: enter image description here

for the red color detection i'm using this code:

import cv2
import numpy as np


    # Take each frame

    frame = cv2.imread('heatmap.png')

    # Convert BGR to HSV
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    # define range of blue color in HSV
    lower_red = np.array([-20, 100, 100])
    upper_red = np.array([13, 255, 255])

    # Threshold the HSV image to get only blue colors
    mask = cv2.inRange(hsv, lower_red, upper_red)

    # Bitwise-AND mask and original image
    res = cv2.bitwise_and(frame,frame, mask= mask)

    k = cv2.waitKey(5) & 0xFF
    if k == 27:


the code above give me al the pixels in red, but i need to determine if the heatmap contour is red, i mean the image contour or border would be a red color not permited area, does anyone how i can do that?

1 answer