In [6]:
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
# Uncomment the next line for use in a Jupyter notebook
# This enables the interactive matplotlib window
%matplotlib notebook
image = mpimg.imread('example_grid1.jpg')
rock_image = mpimg.imread('example_rock1.jpg')
In [7]:
import cv2
import numpy as np
image = mpimg.imread('example_grid1.jpg')
def perspect_transform(img, src, dst):
# Get transform matrix using cv2.getPerspectivTransform()
M = cv2.getPerspectiveTransform(src, dst)
# Warp image using cv2.warpPerspective()
# keep same size as input image
warped = cv2.warpPerspective(img, M, (img.shape[1], img.shape[0]))
# Return the result
return warped
def color_thresh(img, rgb_thresh=(0, 0, 0)):
###### TODO:
# Create an empty array the same size in x and y as the image
# but just a single channel
color_select = np.zeros_like(img[:,:,0])
# Lets get the mask for each color
red = img[:,:,0] > rgb_thresh[0]
green = img[:,:,1] > rgb_thresh[1]
blue = img[:,:,2] > rgb_thresh[2]
# Lets applu the masks and assign 1 where threshold has exceeded
color_select[red] = 1
color_select[green] = 1
color_select[blue] = 1
# Apply the thresholds for RGB and assign 1's
# where threshold was exceeded
# Return the single-channel binary image
return color_select
# Define source and destination points
source = np.float32([[ 119,95 ], [119 , 140], [200 ,95 ], [303 , 140]])
destination = np.float32([[160 ,140 ], [160 ,150 ], [170 , 140], [170 ,150 ]])
plt.imshow(rock_image)
warped = perspect_transform(image, source, destination)
#warped = perspect_transform(image)
colorsel = color_thresh(warped, rgb_thresh=(160, 160, 160))
#plt.imshow(warped)
#plt.imshow(colorsel, cmap='gray')
#plt.show()
ypos, xpos = colorsel.nonzero()
#plt.plot(xpos, ypos, '.')
plt.xlim(0, 320)
plt.ylim(0, 160)
#plt.show()
Out[7]:
In [8]:
import numpy as np
A = np.array([4, 7, 3, 4, 2, 8])
print(A == 4)
In [9]:
import numpy as np
A = np.array([
[12, 13, 14, 12, 16, 14, 11, 10, 9],
[11, 14, 12, 15, 15, 16, 10, 12, 11],
[10, 12, 12, 15, 14, 16, 10, 12, 12],
[ 9, 11, 16, 15, 14, 16, 15, 12, 10],
[12, 11, 16, 14, 10, 12, 16, 12, 13],
[10, 15, 16, 14, 14, 14, 16, 15, 12],
[13, 17, 14, 10, 14, 11, 14, 15, 10],
[10, 16, 12, 14, 11, 12, 14, 18, 11],
[10, 19, 12, 14, 11, 12, 14, 18, 10],
[14, 22, 17, 19, 16, 17, 18, 17, 13],
[10, 16, 12, 14, 11, 12, 14, 18, 11],
[10, 16, 12, 14, 11, 12, 14, 18, 11],
[10, 19, 12, 14, 11, 12, 14, 18, 10],
[14, 22, 12, 14, 11, 12, 14, 17, 13],
[10, 16, 12, 14, 11, 12, 14, 18, 11]])
B = A < 15
B.astype(np.int)
Out[9]:
In [ ]: