import cv2
# Set up video capture device
cap = cv2.VideoCapture(0)
# Initialize variables
previous_frame = None
while True:
# Capture current frame
ret, current_frame = cap.read()
# Convert to grayscale
current_frame_gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)
# Check if previous frame exists
if previous_frame is not None:
# Compute absolute difference between current and previous frame
frame_diff = cv2.absdiff(current_frame_gray, previous_frame)
# Apply thresholding to remove noise
thresh = cv2.threshold(frame_diff, 25, 255, cv2.THRESH_BINARY)[1]
# Find contours of objects in thresholded image
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# Draw bounding box around each contour
for contour in contours:
(x, y, w, h) = cv2.boundingRect(contour)
cv2.rectangle(current_frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
# Update previous frame
previous_frame = current_frame_gray
# Display current frame
cv2.imshow("Motion Detection", current_frame)
# Exit on 'q' key press
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release video capture device and destroy all windows
cap.release()
cv2.destroyAllWindows()
Thursday, April 27, 2023
Motion Detection using OpenCV using python
Face Recognition with OpenCV python code
import cv2
# Load the Haar Cascade face detection classifier
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# Load the trained face recognition model
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read('trained_model.xml')
# Set the video capture device (0 is usually the default webcam)
cap = cv2.VideoCapture(0)
while True:
# Read a frame from the video stream
ret, frame = cap.read()
# Convert the frame to grayscale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Detect faces in the grayscale frame
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5)
# Loop through each face detected
for (x, y, w, h) in faces:
# Crop the face region from the grayscale frame
face_gray = gray[y:y+h, x:x+w]
# Resize the face image to match the training image size
face_gray = cv2.resize(face_gray, (100, 100))
# Predict the label (person) of the face using the trained model
label, confidence = recognizer.predict(face_gray)
# Draw a rectangle around the face and display the predicted label
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.putText(frame, f'Person {label} ({confidence:.2f})', (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
# Display the frame
cv2.imshow('Face Recognition', frame)
# Exit the loop if 'q' is pressed
if cv2.waitKey(1) == ord('q'):
break
# Release the video capture device and close the OpenCV window
cap.release()
cv2.destroyAllWindows()
Note that this code assumes you have already trained a face recognition model and saved it to a file (in this case, trained_model.xml). If you haven't done this yet, you will need to train the model on a dataset of labeled face images before you can use it for recognition.
Object Detection with OpenCV-Python code
import cv2
# Load the pre-trained face detection classifier
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# Load the image
img = cv2.imread('test.jpg')
# Convert the image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Detect faces in the grayscale image
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
# Draw rectangles around the detected faces
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Display the result
cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Wednesday, April 26, 2023
Get column count in MySQL
SELECT count(*) FROM information_schema.columns WHERE table_name = 'vmdata'
Get all column names in MySQL of a table comma separated
For that you can use the following MySQL:
select group_concat(column_name order by ordinal_position) from information_schema.columns where table_schema = 'vops' and table_name = 'vmdata'
Thursday, April 6, 2023
How to check the final SQL query generated by Entity Framework based on the LINQ expression for MySQL database
If you want to check the final SQL query generated by Entity Framework based on the LINQ expression for MySQL database . you can follow the following steps :
1. Connect to your MySQL command line
2. run the following command : SET GLOBAL general_log = 'ON';
Wednesday, March 29, 2023
Server sent charset unknown to the client.
After install mysql 8. I'm trying to connect to a MySQL database from php.
<?php
echo "Hello World!";
?>
</br>
<?php
$link = mysqli_connect('localhost', 'root', 'pass12#####');
if (!$link) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>
</br>
<?php
phpinfo();
?>
</br>
But when I put in username and password I get the error message saying:
Server sent charset unknown to the client. Please, report to the developers
Solution
MySQL 8 changed the default charset to utf8mb4. But some clients don't know this charset. Hence when the server reports its default charset to the client, and the client doesn't know what the server means, it throws this error.
Edit my.cnf, specify the client code, and add the following content.
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
ASP.NET Core
Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...
-
The error message you encountered ("DeleteService FAILED 1072: The specified service has been marked for deletion") indicates tha...
-
may be you need to show serial number in your rdlc report then you can use following syntax for showing 1,2,3... continuous on in table fie...
-
Please Select One Semi-Weekly Monthly Quarterly $('#dd...