Ep#28: Evaluation of Harris corner detection and Laplacian methods in OpenCv+Python using Webcam

Written by:

import cv2 as cv
import imutils
import numpy as np
import sys


# Replace 'your_http_video_stream_url' with the actual HTTP video stream URL
rtsp_video_url = "http://192.168.1.xxx:8000/stream.mjpg"
http_video_url = "http://192.168.1.xxx:8000/stream.mjpg"
# Open the video stream


cap = cv.VideoCapture(rtsp_video_url)
cap.set(cv.CAP_PROP_BUFFERSIZE, 3)
#cap.set(cv.CAP_PROP_TIMEOUT, 60000)
cap1 = cv.VideoCapture(http_video_url)
cap1.set(cv.CAP_PROP_BUFFERSIZE, 3)
#cap1.set(cv.CAP_PROP_TIMEOUT, 60000)
# Check if the video stream is opened successfully
if not cap.isOpened() & cap1.isOpened():
print("Error: Could not open video stream.")
exit()

# Loop to continuously read frames from the video stream
while True:
# Read a frame from the video stream
ret, frame = cap.read()
resized = imutils.resize(frame, width=600)
ret1, frame1 = cap1.read()
resized1 = imutils.resize(frame1, width=600)
# Check if the frame was read successfully
if not ret & ret1:
print("Error: Failed to read frame.")
break

# Display the frame
#cv2.imshow('HTTP Video Stream', resized)
resized1= cv.GaussianBlur(resized1, (3, 3), 0)
resized1_gray = cv.cvtColor(resized1, cv.COLOR_BGR2GRAY)
resized2_gray= np.float32(resized1_gray)
dst = cv.cornerHarris(resized2_gray, 2, 3, 0.04)
dst = cv.dilate(dst, None)

resized2 = cv.Laplacian(resized1_gray, cv.CV_16S, 3)
abs_dst = cv.convertScaleAbs(resized2)
#frame1[dst > 0.01 * dst.max()] = [0, 0, 255]
cv.imshow('Rtsp video stream', abs_dst)
cv.imshow('Rtsp video stream1', dst)
cv.imshow('RTSP', frame1)
# Break the loop if 'q' key is pressed
if cv.waitKey(1) & 0xFF == ord('q'):
break

# Release the video stream and close the OpenCV window
cap.release()
cv.destroyAllWindows()

Leave a comment