Exemplo n.º 1
0
b,g,r = cv2.split(bgr_img)       # get b,g,r
rgb_img = cv2.merge([r,g,b])     # switch it to rgb

(w, h, na) = rgb_img.shape
xstops = [0, 225, 450, h]
ystops = [0, 150, w]
images = []
i = 0

for x in range(3):
    for y in range(2):
        sub_img = rgb_img[ystops[y]:ystops[y+1], xstops[x]:xstops[x+1], :]
        ax = plt.subplot(2, 3, i+1)
        images.append(sub_img)
        my_imshow(sub_img, ax=ax)
        i += 1


def plot_color_histogram(rbg_img):
    color = ('r','g','b')
    for i, col in enumerate(color):
        histr = cv2.calcHist([rbg_img], [i], None, [256], [0,256])
        plt.plot(histr, color=col)
        plt.xlim([0,256])

def test_for_red(rgb_img):
    red_boundaries = ([100, 15, 17],
                      [255, 56, 50])
    # create NumPy arrays from the boundaries
    lower = np.array(red_boundaries[0], dtype = "uint8")
Exemplo n.º 2
0
__author__ = 'Johnson'

import cv2
import numpy as np
from utilities import my_imshow
import matplotlib.pyplot as plt
import matplotlib.cm as cm

filename = "./prob12/prob12.bmp"
image = cv2.imread(filename)
gray_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
(w, h) = gray_img.shape

ystops = [0, 280, 580, w]
images = []
for i in range(3):
    img = gray_img[ystops[i]:ystops[i+1],:]
    img[img>100] = 0
    images.append(img)
    plt.subplot(2,1,1)
    my_imshow(img, cmap=cm.Greys_r)
    # get edges of the image
    filter_image = cv2.blur(img, ksize=(5,5))
    edge_image = cv2.Canny(filter_image, threshold1=0, threshold2=60, apertureSize=3)
    plt.subplot(2,1,2)
    my_imshow(edge_image, cmap=cm.Greys_r)
    plt.show()