import cv2 import numpy as np from PIL import Image from pandas import pd import seaborn as sns import matplotlib.pyplot as plt
img = cv2.imread('I0.jpg')
def Get_data(img): img[img[:,:,2]<250] = 0 img[img[:,:,1]>50] = 0 img[img[:,:,0]<60] = 0 return img
def Get_box(img): img[np.abs(img[:,:,2]-135)>=1] = 255 img[np.abs(img[:,:,1]-135)>=1] = 255 img[np.abs(img[:,:,0]-135)>=1] = 255 return img
img_show = Get_data(img) img_show = cv2.resize(img_show, (2382,1936)) while(True): cv2.imshow('image',img_show) if cv2.waitKey(1) & 0xFF == ord('q'): cv2.destroyAllWindows() break
img_show = cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB) colourImg = Image.fromarray(img_show)
colourPixels = colourImg.convert("RGB") colourArray = np.array(colourPixels.getdata()).reshape(colourImg.size + (3,)) indicesArray = np.moveaxis(np.indices(colourImg.size), 0, 2) allArray = np.dstack((indicesArray, colourArray)).reshape((-1, 5))
df = pd.DataFrame(allArray, columns=["y", "x", "red","green","blue"]) df_lines = df[df.red!=0] df_line_1 = df_lines[df_lines.y>=2000] df_line_1 = df_line_1.sort_values(by=['x']) plt.plot(df_line_1.x, df_line_1.y, 'ro') plt.show()
|