Esempio n. 1
0
def search():

    btn['state'] = NORMAL  #open image button is returened to enabled

    fracturedataset = core.Dataset(
        'trainingimagesgui/'
    )  #initializes the dataset the parameter is the folder in which to get the images for the dataset

    mymodel = core.Model([
        'crack'
    ])  #calls the neural network and it is looking for boxes labelled crack
    print("model imported"
          )  #print function to see if the neural network has been called

    mymodel.fit(fracturedataset)  #train the neuralnetwork on the dataset
    print("finished training custom dataset"
          )  #prints to show that the neural network has finished training
    #testing the neural network
    testimage = utils.read_image(
        filename
    )  #read the varible testimage which has the location of what is stored in variable filename
    print(filename)  #test to see the correct location is being pulled
    endresult = mymodel.predict(
        testimage)  #run the test image on the now trained neural network
    print(
        "prediction complete"
    )  #test to see that the test image has successfully ran on the neural network
    labels, boxes, scores = endresult  #all the parameters the test image will have
    print(labels)  #test to see if the correct label is printed
    print(boxes)  #this will print the coordiantes of the boxes
    print(scores)  #prints a score of how confident the neural network is
    visualize.show_labeled_image(testimage, boxes,
                                 labels)  #display the image on the screen
Esempio n. 2
0
    def classificate(self, image_path):
        image = detecto_utils.read_image(image_path)

        labels, boxes, scores = self.detector.predict(image)
        if len(boxes) == 0:
            return False

        if DEBUG:
            detecto_visualize.show_labeled_image(image, boxes, labels)

        labels_numpy = boxes.detach().cpu().numpy()

        for box in boxes:
            detected_logo = image[int(box[1]):int(box[3]),
                                  int(box[0]):int(box[2]), :]
            if self.classifier.classificate(detected_logo):
                return True

        return False
Esempio n. 3
0
    def predict_one(self):

        # Specify the path to your image
        print(self.imagePath)
        image = utils.read_image(self.imagePath)
        predictions = self.model.predict(image)

        # predictions format: (labels, boxes, scores)
        labels, boxes, scores = predictions

        # ['alien', 'bat', 'bat']
        print(labels)

        #           xmin       ymin       xmax       ymax
        # tensor([[ 569.2125,  203.6702, 1003.4383,  658.1044],
        #         [ 276.2478,  144.0074,  579.6044,  508.7444],
        #         [ 277.2929,  162.6719,  627.9399,  511.9841]])
        print(boxes)

        # tensor([0.9952, 0.9837, 0.5153])
        print(scores)
        visualize.show_labeled_image(image, boxes, labels)
Esempio n. 4
0
from detecto import core, utils, visualize
image = utils.read_image('cat.jpg')
model = core.Model()
labels, boxes, scores = model.predict_top(image)
visualize.show_labeled_image(image, boxes, labels)
Esempio n. 5
0
sample_image = "s1.jpg"

#image = detecto.utils(base_path+sample_image)
# image = cv2.imread(base_path+sample_image)
# cv2.imshow('img',image)
# cv2.waitKey(0)
img = cv2.imread(base_path+sample_image)
# image = read_image(base_path+sample_image)
# plt.imshow(image)
# plt.show()
# cv2.imshow('img',img)
# cv2.waitKey(0)

dataset = Dataset(base_path)
img, targets = dataset[10]
show_labeled_image(img, targets['boxes'], targets['labels'])

labels = ['spiderman', 'venom']
model = Model(labels)
model.fit(dataset)
torch.save(model, 'model.pth')

# directory = r'C:\Users\kapsi\Desktop\WdPO_P\test'
# file_count = sum(len(files) for _, _, files in os.walk(directory))
# if file_count == 0:
#    print('Theres nothing to show! Closing...')
#
# else:
#    pics = list()
#    for i in range(file_count):
#       path = test_data + '{}.jpg'.format(i)
Esempio n. 6
0
def run_detect(image_name):
    image = utils.read_image('static/' + image_name)
    model = core.Model()
    labels, boxes, scores = model.predict_top(image)
    return visualize.show_labeled_image(image, boxes, labels)
Esempio n. 7
0
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

if (cap.isOpened() == False):
    print("Error opening video stream or file")

i = 0
while (cap.isOpened()):
    # Capture frame-by-frame
    ret, frame = cap.read()
    if ret == True:
        cv2.imshow('Video', frame)
        predictions = model.predict(frame)
        labels, boxes, scores = predictions
        if len(scores) > 0 and max(scores) > 0.9:
            visualize.show_labeled_image(frame, boxes[0], labels[0])
            if i == 0:
                win32api.MessageBox(0, 'KNIFE DETECTED. SAVING IMAGE.',
                                    'ALERT', 0x00001000)
            x1, y1, x2, y2 = boxes[0]
            img = cv2.rectangle(frame, (int(x1), int(y1)), (int(x2), int(y2)),
                                (0, 255, 0), 3)
            cv2.imshow('detected', frame)
            cv2.waitKey(0)
            cv2.destroyAllWindows()
            cv2.imwrite('knifedetected' + str(i) + '.jpg', frame)
            sendmail(i)
            i = i + 1

    # Press Q on keyboard to  exit
        ch = cv2.waitKey(1)
Esempio n. 8
0
def detecto_m(pic):
    image = utils.read_image(pic)
    model = core.Model()
    labels, boxes, scores = model.predict_top(image)
    result = visualize.show_labeled_image(image, boxes, labels)
    return result