cv2 replace color

Solutions on MaxInterview for cv2 replace color by the best coders in the world

showing results for - "cv2 replace color"
Anton
26 Jan 2018
1#!/usr/local/bin/python3
2import cv2 as cv
3import numpy as np
4
5# Load the aerial image and convert to HSV colourspace
6image = cv.imread("aerial.png")
7hsv=cv.cvtColor(image,cv.COLOR_BGR2HSV)
8
9# Define lower and uppper limits of what we call "brown"
10brown_lo=np.array([10,0,0])
11brown_hi=np.array([20,255,255])
12
13# Mask image to only select browns
14mask=cv.inRange(hsv,brown_lo,brown_hi)
15
16# Change image to red where we found brown
17image[mask>0]=(0,0,255)
18
19cv.imwrite("result.png",image)