testing and added data for testing similarity
This commit is contained in:
48
main1.py
48
main1.py
@ -1,33 +1,27 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
# from matplotlib.pyplot import imshow
|
||||
# from google.colab.patches import cv2_imshow
|
||||
# !wget https://i.stack.imgur.com/sDQLM.png
|
||||
#read image
|
||||
image = cv2.imread( "croped.png")
|
||||
import json
|
||||
|
||||
width = 350
|
||||
height = 450
|
||||
dim = (width, height)
|
||||
data = None
|
||||
|
||||
image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
|
||||
with open('dataset.json') as f:
|
||||
data = json.load(f)
|
||||
# print(len(data))
|
||||
|
||||
#convert to gray
|
||||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
#performing binary thresholding
|
||||
kernel_size = 3
|
||||
ret,thresh = cv2.threshold(gray,200,255,cv2.THRESH_BINARY)
|
||||
print(data)
|
||||
dictionary = [
|
||||
{
|
||||
"id" : 4,
|
||||
"datanya" : "ini yang ke4"
|
||||
}
|
||||
]
|
||||
|
||||
#finding contours
|
||||
cnts = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
|
||||
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
|
||||
# # Serializing json
|
||||
# json_object = json.dumps(dictionary, indent=4)
|
||||
|
||||
#drawing Contours
|
||||
radius =2
|
||||
color = (30,255,50)
|
||||
cv2.drawContours(image, cnts, -1,color , radius)
|
||||
# cv2.imshow(image) commented as colab don't support cv2.imshow()
|
||||
cv2.imshow("",image)
|
||||
# cv2.waitKey()
|
||||
cv2.waitKey(0)
|
||||
data.extend(dictionary)
|
||||
json_object = json.dumps(data, indent=4)
|
||||
print(json_object)
|
||||
|
||||
# Writing to sample.json
|
||||
with open("dataset.json", "w") as outfile:
|
||||
outfile.write(json_object)
|
||||
Reference in New Issue
Block a user