ソニーグループ合同 データ分析コンペティションに参加中。
signate.jp
- 訓練データとテストデータでサイコロの数が違うので、クラス分類などでは不可。
- OpenCVの輪郭抽出でサイコロをクロッピング→画像分類→目の数を合計 で行けるのでは?
- →行けそうではあるが、うまく分離できていない(2つのサイコロが重なっている)箇所が多くある。どうする?
train_y = np.load(data_path + '/y_train.npy')
train_x = np.load(data_path + '/X_train.npy').reshape(-1, 20, 20)
def drow_rect(img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
_, thresholded = cv2.threshold(gray, 128, 255, cv2.THRESH_BINARY)
contours, _ = cv2.findContours(thresholded, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
croped = []
print(len(contours))
for contour in contours:
if cv2.contourArea(contour) > 100:
x, y, w, h = cv2.boundingRect(contour)
croped.append(cv2.resize(img.copy()[y:y+w, x:x+w, :], (64, 64)))
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
return img, croped
def show_img(arr):
resized_image = cv2.resize(arr, (224,224))
plt.imshow(resized_image)
plt.show()
for i, im in enumerate(train_x[:2]):
org = im.copy()
im = cv2.cvtColor(im, cv2.COLOR_GRAY2BGR)
im = cv2.resize(im, (224,224))
im, croped = drow_rect(im)
show_img(im)
for im in croped:
show_img(im)
show_img(org)
print("ans: {}".format(train_y[i]))