示例#1
0
    def test_detection_softmax_model(self):
        img_path = self.find_dnn_file("dnn/person-detector.png")
        weights = self.find_dnn_file("dnn/squeezenet_softmax.caffemodel",
                                     required=False)
        config = self.find_dnn_file("dnn/squeezenet_softmax.prototxt")
        if weights is None or config is None:
            raise unittest.SkipTest(
                "Missing DNN test files (dnn/squeezenet_v1.1.{prototxt/caffemodel}). Verify OPENCV_DNN_TEST_DATA_PATH configuration parameter."
            )

        frame = cv.imread(img_path).astype(np.uint8)
        model = cv.dnn_ClassificationModel(config, weights)
        model.setInputSize(224, 224)
        model.setInputCrop(True)

        out = model.predict(frame)
        for i in range(10):
            frame2 = np.clip(frame + np.random.randint(0, 2, frame.shape), 0,
                             255).astype(np.uint8)
            out2 = model.predict(frame2)
            ref = out2
            try:
                normAssert(self,
                           out[0],
                           ref[0],
                           msg="prediction probility in max. " +
                           str(np.max(np.abs(out[0] - ref[0]))))
            except Exception as e:
                print(e.args)
示例#2
0
    def test_classification_model(self):
        img_path = self.find_dnn_file("dnn/googlenet_0.png")
        weights = self.find_dnn_file("dnn/squeezenet_v1.1.caffemodel")
        config = self.find_dnn_file("dnn/squeezenet_v1.1.prototxt")
        ref = np.load(self.find_dnn_file("dnn/squeezenet_v1.1_prob.npy"))

        frame = cv.imread(img_path)
        model = cv.dnn_ClassificationModel(config, weights)
        model.setInputSize(227, 227)
        model.setInputCrop(True)

        out = model.predict(frame)
        normAssert(self, out, ref)
示例#3
0
    def test_classification_model(self):
        img_path = self.find_dnn_file("dnn/googlenet_0.png")
        weights = self.find_dnn_file("dnn/squeezenet_v1.1.caffemodel", required=False)
        config = self.find_dnn_file("dnn/squeezenet_v1.1.prototxt")
        ref = np.load(self.find_dnn_file("dnn/squeezenet_v1.1_prob.npy"))
        if weights is None or config is None:
            raise unittest.SkipTest("Missing DNN test files (dnn/squeezenet_v1.1.{prototxt/caffemodel}). Verify OPENCV_DNN_TEST_DATA_PATH configuration parameter.")

        frame = cv.imread(img_path)
        model = cv.dnn_ClassificationModel(config, weights)
        model.setInputSize(227, 227)
        model.setInputCrop(True)

        out = model.predict(frame)
        normAssert(self, out, ref)
示例#4
0
import os
import cv2

net = cv2.dnn_ClassificationModel('./model/plate_model.xml',
                                  './model/plate_model.bin')

net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

path = os.path.dirname(__file__)

HEIGHT = 32
WIDTH = 32


def predict(img):
    if type(img) == str: img = cv2.imread(img, 0)
    elif img.ndim > 2: img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    #if img[0][0] > 1:   img = img / 255.
    img = cv2.resize(img, (WIDTH, HEIGHT))
    prediction = net.predict(img)[0][0]

    return prediction


if __name__ == "__main__":

    for i in range(9):

        img = cv2.imread('./data/' + str(i) + '.png')