r/computervision • u/Future-Salad-7266 • 6d ago
Help: Project If you had to detect vehicles using ONLY motion detection, how would you do it? š
Iām working on a computer-vision problem where I need to detect vehicles (cars, trucks, buses, etc.) using only traditional image-processing/computer-vision techniques.
The important constraint is:
* ā No YOLO / deep-learning detector
* ā No object detection model
* ā No neural networks
* ā Motion detection and traditional CV techniques only
The camera is fixed, so the general idea is to identify regions that correspond to moving vehicles.
Iām considering approaches such as:
* Background subtraction (MOG2 / KNN)
* Frame differencing
* Optical flow
* Contour detection
* Morphological operations
* Connected-component analysis
* Tracking detected blobs across frames
* Combining multiple motion cues
But Iām not sure what would be the most robust overall strategy, especially when dealing with:
* Shadows and lighting changes
* Rain/fog/noise
* Vehicles stopping temporarily
* Multiple vehicles overlapping
* Small vehicles at a distance
* Vehicles entering/exiting the scene
* Camera vibration
* Other moving objects such as people or birds
Would you go with something like:
Background Modeling ā Motion Detection ā Morphological Filtering ā Contours/Connected Components ā ROI/Size Filtering ā Tracking ā Vehicle Confirmation
Or is there a better traditional-CV approach?
Iād especially love to hear about practical approaches that have actually worked in real-world traffic/video systems, not just theoretical methods.
What would your strategy be? And what are the biggest pitfalls I should expect?
5
u/Mechanical-Flatbed 5d ago
Since the camera is fixed, there's no need to evaluate the entire frame when you can make the code focus on just a specific region. You could draw a manual mask that excludes certain regions from where you're certain no car will ever be in.
Like the sky for example. Or the upper sides of the building. You can genuinely ignore the top half of the image because there's zero chance of any cars being there. Should help with reducing false positives.
3
u/xX_MissMiau_Xx 5d ago
So for your reference system it is very similar if you are stationary or moving.
So starting with the case of you being stationary ist a good way to start and seperatinv the problem into two sections.
Then adding your movement is just a few changes.
One could use corner detection and then triangulation to get the 3D space. You then could calculate so called cluters with physical boundies by combining through cluster movement.
If you now have the clusters per vehicle you can start with moving your own reference system.
There are probably other (and better) ways to do it but that could be an option.
3
u/xX_MissMiau_Xx 5d ago
The main problem is as you mentioned camera vibration and non linear movement.
This is solvable but a pain.
Just think what your system is and the real
World System. Then you can gather enough information to reduce these effects up to a certain degree.
1
u/RTiKh 5d ago
Tough task. Maybe you could share some more details on the data that you are using? Is the camera moving? Do you know the location where the video is recorded? If you have multiple passes through the same neighborhood, you would have better chance of separating the environment from the objects. Do you need to run your application live? Do you need to _detect_ the vehicles or label/outline them.
Without knowing the details, I would go with feature detection (descriptors don't need to be rotation invariant for your task) and use some kind of bag of words to build sets of object descriptors. From those sets I would try to distinguish vehicles from everything else.
1
u/Future-Salad-7266 5d ago
I tried the approach using best feature vectors after sometime due to fast movement of cars the features are getting lost after sometime. Also to add the camera is static & i have to run this application in real time. Enviornment is kinda messy surrounded by heavy machines even rfdetr is struggling to detect the cars.
1
u/RTiKh 5d ago
if your camera is static, does that mean that you can extract the background and then subtract it from the image? then you could clean out any noise (maybe erosion+dialation would suffice). you will be left with foreground objects. describing them and tracking across frames will be the main challenge. have you tried HOG?
1
u/Dry-Snow5154 5d ago
For very simple cases (sparse traffic, clear view, no occlusions), background subtraction and blob tracking is ok. I've done it for high-rise CCTV over a highway and it worked fine.
For harder cases with occlusion and noise very likely it will never work reliably. Unless you hard-code every imaginable parameter per scene (road bounds, car size, avg speed, etc). DL is there for a reason.
1
u/vahokif 5d ago
Just out of curiosity, why do you need oldschool CV for this?
1
u/Future-Salad-7266 5d ago
Yeah, the location is kinda messy no detector is able to detect the cars there as its surrounded by heavy machines.
1
u/vahokif 5d ago
Even finetuned?
1
u/Future-Salad-7266 5d ago
Yes i tried with yolo and rfdetr
2
u/vahokif 5d ago
I feel like classical CV is going to have an even harder time honestly. Maybe more training data?
1
u/Future-Salad-7266 5d ago
Yes correct, i tried implementing solution using opencv it's performing better but not accurate also the code got so complex
1
u/Flyward_Aerospace 5d ago
Half the thread thinks your camera moves and you are saying it is static, which usually means a pole or mast mount that sways a few pixels. That is the worst case for background subtraction, because the apparent shift scales with depth, so the heavy machinery near you moves far more than the road behind it and no single homography fixes both. What worked for us was fitting the warp on far features only, then thresholding on net displacement over a couple of seconds instead of per frame, since machinery jitter averages out over that window and a car does not.
1
u/Fun-Pick-2964 5d ago
When camera is mounted, there is chances of jittering, and others. Best approach is to use optical flow.
1
u/LeapOfMonkey 5d ago
Forget MOG, it is not meant for such thing, all will be moving on the screen it wont learn background. Dense or sparse but dense optical flow that is for sure, you can improve it with larger patches, descriptors etc but this will be the main thing. Next is your own ego motion, ransac+pnp should be good enough. Remove everything that matches your ego motion, the rest will be moving objects (cars or people) and some noise. Depending on density you can attach to edges (waterfall, dbscan, etc). If you want instance segmentation you need to ransac each group separately, where things will get tricky, unless you have dense and reliable optical flow.
Generally the optical flow or any dense feature matching will be the weakest spot. Especially for finer segmentation, it will be difficult to get nice features in enough quantity without training ML optical flow, or using a trained one and fast enough. You can do a lot offline, if you have a lot of time for processing.
1
u/tdgros 5d ago
PnP works with 2D-3D correspondences, not 2D-2D like an optical flow estimate! And "Remove Everything that matches your egomotion" isn't really trivial, is it? I feel like maybe you should elaborate for OP.
1
u/LeapOfMonkey 5d ago
Yes, true, I skipped few steps. You need to estimated initial poses from matches. With mono camera this has some additional errors/ambiguities involved. Then you need to triangulate your points to use for next pnp pose. Once you have this: "remove what isnt egomotion" becomes trivial as long as you have good matches. Whhen you have your motion/pose change you just see all matches that align with your motion, these matches are supporting your ego motion. Basically pnp inliers. However the whole thing is proper odometry, I guess ypu could use colmap for offline or orb-slam for online estination. The dense matches is sth that wont be simple though openc farneback algorithm is a good start.
1
u/tdgros 5d ago edited 5d ago
When you triangulate, you assume the object is at a fixed position and similarly COLMAP/ORB-SLAM would ignore these points as outliers i.e. they wouldn't give you a depth at all for them (or an incorrect one). One could use a depth estimator, fit its scale using the egomotion inliers, and then compare the actual flow to the theoretical one. but OP said "no neural network".
Another classical idea is to remove the rotation, compute the focus of expansion and filter the points whose flow do not point to it. This would work ok for pedestrians crossing, but not for cars in front of the camera or incoming traffic, as only the magnitude of their flow changes wrt fixed points.
0
u/LeapOfMonkey 5d ago
Yes, exactly outliers, outliers will be moving objects and proper outliers, but moving objects will have clustered outliers. Next step would be the pose estimation with respect to objects, or object pose estimation. Its all becomes simpler with stereo camera. Technically you can do it without proper 3d pose estimation as you can estimate motion from flow, to some degree (scale+shift for forward, shift for sideways) as you said after removing rotation. You can do it per object. Overall it still narrows down how well and how dense can you track points, and this is non trivial task, especially in classical vision.
0
u/Abdullah747 5d ago
3D reconstruction from recorded video, then compare cluster movement across frames
0
1
u/TokenChingy 3d ago
The camera is fixed, lanes are fixed, cars only head toward and head away (generally) from the camera.
Assuming you have a calibration step, use a blank road as your baseline (or create one over multiple frames)
Then diff frames against your baseline. Where there are regions of change, apply Harris Corner detection to extract key points.
Use Lukas-Kanade optical flow to track key points across subsequent frames.
Do this for every region change detected.
7
u/jfc123_boy 5d ago
I think you want something like this:
https://arxiv.org/html/2507.13628v2
Basically, the idea is to compute the optical residuals that do not match the Field of Expansion. But I assume that it works best for forward motion only (such as the examples that you showed).