You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to do edge segmentation of rocks,but got this error.
before this,I did the region segmentation of rocks in the same rock picture. Didn’t get this error.
I used the following method to transform json to label.
ensure_dir(INPUT_DIR)
# ensure_dir(OUTPUT_DIR)
category_types = ["background", "chips"]
# empty_dir(OUTPUT_DIR)
# empty_dir(label_DIR)
# empty_dir(side_DIR)
""" Browse through all marked json files """
for file in iglob(INPUT_DIR + '/*.json'):
with open(file, 'r', encoding='utf-8') as f:
""" Load json files """
data = json.load(f)
""" Save image file """
j_name = file.split("\\")[-1]
ts = j_name.split(".")
title = ts[0]
file_name = join(img_DIR, "%s.jpg"%title)
print(file_name, file)
img_ori = cv2.imread(file_name, cv2.IMREAD_GRAYSCALE) #3通道变灰度图单通道
#cv2.imshow('a',img_ori)
size_ori = img_ori.shape
#print(size_ori)
""" Get image width x height """
mask = np.zeros((size_ori[0], size_ori[1]), dtype="uint8") #全黑图
sideImg = np.zeros((size_ori[0], size_ori[1]), dtype="uint8")
""" Process each shape (annotation) """
for shape in data['shapes']:
category = shape["label"]
points = shape["points"]
# 填充
points_array = np.array(points, dtype=np.int32)
mask = cv2.fillPoly(mask, [points_array], (255, 255, 255), category_types.index(category))
sideImg = cv2.drawContours(sideImg, [points_array], -1, (255, 255, 255), 3, category_types.index(category))
# cv2.imshow("mak:", mask)
# cv2.polylines
save_name = join(label_DIR, title) + ".png"
cv2.imwrite(save_name, mask)
save_name = join(side_DIR, title) + ".png"
cv2.imwrite(save_name, sideImg)
Anyone met the same error?
The text was updated successfully, but these errors were encountered:
I want to do edge segmentation of rocks,but got this error.
before this,I did the region segmentation of rocks in the same rock picture. Didn’t get this error.
I used the following method to transform json to label.
ensure_dir(INPUT_DIR)
Anyone met the same error?
The text was updated successfully, but these errors were encountered: