File size: 917 Bytes
b787ced
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
import cv2
import tensorflow as tf
import numpy as np
model = tf.keras.models.load_model("crack_detector.h5")

# Use HTTP instead of HTTPS
url = "<Embedd-your-URL>" #Iinstall droidcam on phone and insert the URL
cap = cv2.VideoCapture(url)

while True:
    ret, frame = cap.read()
    if not ret:
        print("Failed to grab frame. Check IP/Port and make sure phone/laptop are on same WiFi.")
        break
    
    img = cv2.resize(frame, (224, 224))
    img = img.astype("float32")/255.0
    img = np.expand_dims(img, axis=0)

    pred = model.predict(img, verbose=0)[0][0]
    label = "No Crack" if pred<0.9 else "Crack Detected"

    color = (0,255,0) if label=="No Crack" else (0,0,255)
    cv2.putText(frame, label, (20,40), cv2.FONT_HERSHEY_SIMPLEX,1, color, 2)

    cv2.imshow("Wall crack detection", frame)
   
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()