Вы можете избавиться от порога, пока вы исправите свое освещение (метод 1, указанный ниже), если нет, вам может понадобиться простой метод классификатора (например, метод кластеризации, метод 2) в сочетании с подключенными компонентами и предположениемна месте растения или цвета, чтобы назначить обнаруженный класс для растения.
from scipy.misc import imread
import matplotlib.pyplot as plt
import matplotlib.patches as patches
%matplotlib inline
import matplotlib
import numpy as np
# read the image
img = imread('9v5wv.png')
# show the image
fig,ax = plt.subplots(1)
ax.imshow(img)
ax.grid('off')
# show the r,g,b channels separately.
for n,d in enumerate([('r',0),('g',1),('b',2)]):
k,v = d
plt.figure(n)
plt.subplot(131)
plt.imshow(arr[:,:,v],cmap='gray')
plt.grid('off')
plt.title(k)
plt.subplot(133)
_=plt.hist(arr[:,:,v].ravel(),bins=100)
# method 1, rgb thresholding will not work when lighting changes
arr = img
r_filter = lambda x: x[:,:,0] < 100
g_filter = lambda x: x[:,:,1] > 80
b_filter = lambda x: x[:,:,2] < 200
mask=np.logical_and(np.logical_and(r_filter(arr),g_filter(arr)),b_filter(arr))
plt.imshow(mask,cmap='gray')
plt.grid('off')
![enter image description here](https://i.stack.imgur.com/4jGui.png)
# method 2, kmeans clustering
from sklearn.cluster import KMeans
arr = matplotlib.colors.rgb_to_hsv(img[:,:,0:3])
# ignore v per Yves Daoust
data = np.array(arr[:,:,0:2])
x,y,z = data.shape
X = np.reshape(data,(x*y,z))
kmeans = KMeans(n_clusters=6, random_state=420).fit(X)
mask = np.reshape(kmeans.labels_,(x,y,))
plt.imshow(mask==0,cmap='gray')
plt.grid('off')
![enter image description here](https://i.stack.imgur.com/XPLGK.png)