-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatistical_property.py
31 lines (26 loc) · 1.49 KB
/
statistical_property.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Import the required libraries for classification
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
# Load the dataset of labeled car images and their corresponding labels
# (You would need to create your own labeled dataset)
X = load_images() # This function should return a list of images, each image represented as a 1D array
y = load_labels() # This function should return a list of labels, one for each image in X
# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Create a Random Forest classifier and fit it to the training data
clf = RandomForestClassifier(n_estimators=100, random_state=42)
clf.fit(X_train, y_train)
# Evaluate the accuracy of the classifier on the test data
accuracy = clf.score(X_test, y_test)
print("Accuracy: %.2f%%" % (accuracy * 100.0))
# Use the classifier to predict the class of a new image
# (Assuming the new image is named "new_image.jpg")
new_image = io.imread("C:\\Users\\roshn\\OneDrive\\Desktop\\Multimedia Processing\\Images_Car_Damage_Dataset.zip\\img.jpg", as_gray=True)
g = feature.greycomatrix(new_image, [5], [0], levels=256, symmetric=True, normed=True)
features = feature.greycoprops(g, 'homogeneity', 'contrast', 'energy')
features = np.ravel(features)
prediction = clf.predict([features])[0]
if prediction == 1:
print("The car is damaged.")
else:
print("The car is not damaged.")