In [ ]:
from utils_io import read_json, load_items
params = read_json('parameters.json')
ITEM_FOLDER = params['item_folder']
items = load_items(ITEM_FOLDER)
In [ ]:
from matplotlib import pyplot as plt
%matplotlib inline
In [ ]:
import cv2, numpy as np
from ipywidgets import interact
from utils import imread_rgb, imread_gray
def load_and_plot(item1, view1, item2, view2):
prefix = ITEM_FOLDER + '/' + item1 + '/' + item1 + '_' + view1
filename = prefix + '_mask.pgm'
mask1 = imread_gray(filename)
prefix = ITEM_FOLDER + '/' + item2 + '/' + item2 + '_' + view2
filename = prefix + '_mask.pgm'
mask2 = imread_gray(filename)
if not mask1 is None:
plt.subplot(121); plt.imshow(mask1,cmap='gray'); plt.axis('off');
if not mask2 is None:
plt.subplot(122); plt.imshow(mask2,cmap='gray'); plt.axis('off');
plt.show();
if not mask1 is None:
cnt1, _ = cv2.findContours(mask1, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
img1 = np.zeros(mask1.shape)
cv2.drawContours(img1, cnt1, 0, 255)
plt.subplot(121); plt.imshow(img1,cmap='gray'); plt.axis('off');
if not mask2 is None:
cnt2, _ = cv2.findContours(mask2, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
img2 = np.zeros(mask2.shape)
cv2.drawContours(img2, cnt2, 0, 255)
plt.subplot(122); plt.imshow(img2,cmap='gray'); plt.axis('off');
plt.show();
if not mask1 is None and not mask2 is None:
print('Match:')
print('I1: %f' % cv2.matchShapes(cnt1[0], cnt2[0], cv2.cv.CV_CONTOURS_MATCH_I1, 0.0))
print('I2: %f' % cv2.matchShapes(cnt1[0], cnt2[0], cv2.cv.CV_CONTOURS_MATCH_I2, 0.0))
print('I3: %f' % cv2.matchShapes(cnt1[0], cnt2[0], cv2.cv.CV_CONTOURS_MATCH_I3, 0.0))
In [ ]:
views = ['top_01','top-side_01','top-side_02','bottom_01','bottom-side_01','bottom-side_02']
interact(load_and_plot,item1=items,view1=views,item2=items,view2=views);
In [ ]: