🎉 Mask R-CNN with PCA for Video Processing 📹
Final Result
Youtube Video 😀
🚀 Load the Pre-trained Model
Load the Mask R-CNN model pre-trained on COCO dataset and set it to evaluation mode. 🧠
🌈 Define COCO Object Names and Colours
Define the object names and assign random colours for visualization. 🎨
🖌️ Apply Mask to Image
Apply the given mask to the image with transparency. 🖼️
📍 Calculate Mask Centre
Calculate the centre of the binary mask using the centroid formula. 📏
📐 Compute Principal Axes with PCA
Compute the principal axes of the mask using PCA. 🧮
🎥 Video Processing
📂 Specify Paths
Specify the input and output video paths. 📁
🎬 Capture Video
Capture video from the file and set up the video writer. 🎥
🔄 Process Each Frame
Process each frame, apply masks, draw bounding boxes, and save the output video. 🎞️
The principal axes are computed using PCA:
center=pca.mean direction1=pca.components[0]×pca.explainedvariance[0]direction2=pca.components[1]×pca.explainedvariance[1]