Пример #1
0
def mplot(img, img2=none):

    cv2.namedwindow('img', cv2.window_normal)
    cv2.movewindow('img', 600, 300)
    cv2.imshow('img', img)
    if img2 is not none:
        cv2.namedwindow('img2', cv2.window_normal)
        cv2.movewindow('img', 600, 600)
        cv2.imshow('img2', img2)
    cv2.waitkey(0)
    cv2.destroyallwindows()
Пример #2
0
def get_frame():
    cap =cv2.VideoCapture(0+cv2.CAP_DSHOW)
    while True:
        _, frame = cap.read()
        frame=cv2.flip(frame,1)
        x = FRDist(frame,enck,Names)
        imgencode = cv2.imencode('.jpg',frame)[1]
        stringData= imgencode.tobytes()
        yield(b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n'+ stringData +b'\r\n')

    cap.release()
    cv2.destroyallwindows()
Пример #3
0
def take_snapshot():
    number = random.randint(0, 100)
    videoCaptureObject = cv2.VideoCapture(0)
    result = True
    while (result):
        ret, frame = videoCaptureObject.read()
        image_name = "img" + str(number) + ".png"
        cv2.imwrite(image_name, frame)
        start_time = time.time
        result = False
    return img_name
    print("snapshot taken")
    videoCaptureObject.release()
    cv2.destroyallwindows()
Пример #4
0
def clean(path, show=False):
    image = cv2.imread(path)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    image = cv2.medianBlur(gray, 5)

    kernel = np.ones((5, 5), np.uint8)
    alpha, beta = 1, 25

    image = cv2.erode(image, kernel, iterations=1)
    image = cv2.dilate(image, kernel, iterations=1)
    image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel)
    adjusted = cv2.convertScaleAbs(image, alpha=alpha, beta=beta)

    if show:
        cv2.imshow("result", image)
        cv2.waitKey(0)
        cv2.destroyallwindows()
    # Save Result
    cv2.imwrite('temp.jpg', image)
Пример #5
0
 def display_image(self, img: np.ndarray):
     """Display an image until window is closed."""
     cv2.imshow('Image', img)
     cv2.waitKey(0)
     cv2.destroyallwindows()
Пример #6
0

cap = cv2.VideoCapture("http://192.168.43.1:8080/video")
while True:
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    canvas = detect(gray, frame)
    # show the output montage
    #montage = build_montages(results, (1024, 1024), (1, 1))[0]
    #cv2.imshow("Results", montage)
    cv2.imshow("results", canvas)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyallwindows()
"""
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--images", required=True,
	help="path to out input directory of images")
ap.add_argument("-m", "--model", required=True,
	help="path to pre-trained model")
args = vars(ap.parse_args())

# load the pre-trained network
print("[INFO] loading pre-trained network...")
model = load_model(args["model"])

# grab all image paths in the input directory and randomly sample them
#imagePaths = list(paths.list_images(args["images"]))
Пример #7
0
def run():
    net = cv2.dnn.readNet(opt.weights, opt.cfg)
    classes = load_classes(opt.names)

    layer_names = net.getLayerNames()
    outputlayers = [
        layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()
    ]
    colors = np.random.uniform(0, 255, size=(len(classes), 3))

    #loading video from webcam
    cap = cv2.VideoCapture(0)
    font = cv2.FONT_HERSHEY_SIMPLEX

    while True:
        _, frame = cap.read()
        height, width, channels = frame.shape

        blob = cv2.dnn.blobFromImage(
            frame, 0.00392, (320, 320), (0, 0, 0), True,
            crop=False)  #reduce the frame to 320 * 320 pixels

        net.setInput(blob)
        outs = net.forward(outputlayers)

        #Showing info on screen/ get confidence score of algorithm in detecting an object in blob
        class_ids = []
        confidences = []
        boxes = []
        for out in outs:
            for detection in out:
                scores = detection[5:]
                class_id = np.argmax(scores)
                confidence = scores[class_id]
                if confidence > 0.3:
                    #object detected
                    center_x = int(detection[0] * width)
                    center_y = int(detection[1] * height)
                    w = int(detection[2] * width)
                    h = int(detection[3] * height)

                    #cv2.circle(img,(center_x,center_y),10,(0,255,0),2)
                    #rectangle co-ordinaters
                    x = int(center_x - w / 2)
                    y = int(center_y - h / 2)
                    #cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)

                    boxes.append([x, y, w, h])  #put all rectangle areas
                    confidences.append(
                        float(confidence)
                    )  #how confidence was that object detected and show that percentage
                    class_ids.append(
                        class_id)  #name of the object that was detected

        indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.4, 0.6)
        for i in range(len(boxes)):
            if i in indexes:
                x, y, w, h = boxes[i]
                if i == 0:
                    label = str(classes[class_ids[i]])
                    confidence = confidences[i]
                    color = colors[class_ids[i]]
                    cv2.rectangle(frame, (x, y), (x + w, y + h), color, 2)
                    cv2.putText(frame, label + " " + str(round(confidence, 2)),
                                (x, y + 30), font, 0.5, (255, 255, 255), 1)

        cv2.imshow("Image", frame)
        key = cv2.waitKey(
            1
        )  #wait 1ms before the loop starts again and we process the next frame

        if key == 27:
            break
            #esc key stops the process
    cap.release()
    cv2.destroyallwindows()