Hi, this is Nayon. ShapeAnnotator (shapes-v1.pkl) is my first machine learning–based AI model that can identify basic geometrical shapes such as triangle, circle, and rectangle. For best accuracy, you should use pure black-and-white images as shown in the example. Here's the python code and example.

import matplotlib.pyplot as plt
import joblib
import cv2

model=joblib.load('give the model (shapes-v1.pkl) path here')
shape = {1:'circle', 
         2:'rectangle', 
         3:'triangle'}
image = cv2.imread('give the image path here',cv2.IMREAD_GRAYSCALE)
edges = cv2.Canny(image, 0,255)
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
pic=image.copy()
for i in range(0,len(contours),1):
    x, y, w, h = cv2.boundingRect(contours[i])
    cropped=image[y:y+h, x:x+w]
    cropped=cv2.resize(cropped,(32,32))
    cropped=cropped/255.0
    cropped=cropped.reshape(1,-1)
    result=model.predict(cropped)
    cv2.putText(pic,
                shape[result[0]],
                (x,y),            
                cv2.FONT_HERSHEY_SIMPLEX,
                w/100,           
                (100, 100, 100),  
                2)              
plt.imshow(pic)

Input Main Example Output Generated Example

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support