如何检查图片中是否有一种颜色?

时间:2019-06-19 14:33:13

标签: python image-processing colors

我需要检查图片是否是马克杯。背景必须有一种颜色。 问题:如何检测到这一点?

我为此尝试了直方图分析,但没有成功。

İnput İmage

from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from mrcnn.config import Config
from mrcnn.model import MaskRCNN
from matplotlib import pyplot
from matplotlib.patches import Rectangle
import cv2


# draw an image with detected objects
def draw_image_with_boxes(filename, boxes_list):
# load the image
data = pyplot.imread(filename)
# plot the image
pyplot.imshow(data)
# get the context for drawing boxes
ax = pyplot.gca()
# plot each box
for box in boxes_list:
    # get coordinates
    y1, x1, y2, x2 = box
    # calculate width and height of the box
    width, height = x2 - x1, y2 - y1
    # create the shape
    rect = Rectangle((x1, y1), width, height, fill=True, color='black')
    # draw the box
    ax.add_patch(rect)
# show the plot
pyplot.show(), pyplot.axis("off")


# define the test configuration
class TestConfig(Config):
NAME = "test"
GPU_COUNT = 1
IMAGES_PER_GPU = 1
NUM_CLASSES = 1 + 80


# define the model
rcnn = MaskRCNN(mode='inference', model_dir='./', config=TestConfig())
# load coco model weights
rcnn.load_weights('mask_rcnn_coco.h5', by_name=True)
# load photograph
img = load_img('AP1.jpg')
img = img_to_array(img)
# make prediction
results = rcnn.detect([img], verbose=0)
# visualize the results
draw_image_with_boxes('AP1.jpg', results[0]['rois'])

img = cv2.imread('AP1.jpg', 0)
pyplot.hist(img.ravel(), 256, [0, 256]); pyplot.show()

Output İmage

Histogram

0 个答案:

没有答案