Find movement distance between two frames -- python - python

I have a short video of a moving object. for some reason I need to estimate the object's movement distance between two specific frames. It is not necessary to be exact.
Does anyone know how I can do this in python and opencv or any image processing library?
Thanks

I don't know in opencv, there is for sure something similar but you can easily do it with scikit-image module. I do it on a regular basis to align frames.
See this example here:
https://scikit-image.org/docs/dev/auto_examples/transform/plot_register_translation.html#sphx-glr-auto-examples-transform-plot-register-translation-py
EDIT: I found something very similar in opencv here
https://docs.opencv.org/4.2.0/db/d61/group__reg.html

Related

How to check if two points (characters) in an image are at the same horizontal level?

I'm a beginner and would like to know methods that could be used to check if two characters in an image are at the same horizontal level. Any help would be appreciated.
I'm looking for a simple method using python image processing.
Use OpenCV or PIL library. These libraries can help finding the bounding box/rectangle of the characters. Then you can use that info to compare positions and verify if they are on same level.
check: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html

Python - differentiating similar images

I am trying to detect the differences in two images in python (object present or not). I tried different approaches with opencv and pillow for python. The goal is to check if an object is present or not. And if possible i want to extract the coordinates of the changes (with a bounding box)
The problem is, that the images are not 100% identical. There is always a very slight change in angle or lighting. Thresholding didnt do the trick as expected....
Is there any other approaches that you would suggest?
Thanks in advance
You can use the Structural similarity index for a robust image comparison:
https://scikit-image.org/docs/dev/auto_examples/transform/plot_ssim.html
This is implemented on scikit-image package.

Rotating and cropping a ROI from minAreaRect() OpenCV python

I'm trying to make a program that rotates and crops an image ROI (without losing a single pixel of the frame) based just on what minAreaRect() returns (from seeing what it can mark with drawContours).
Now since I don't understand what the function returns other than the rotation angle(list [0:1]) I'm struggling to make that myself. All I found on the internet was a Stack Overflow question with code that wasn't really explained very well and didn't realy work (atleast for openCV 3.6 not)
May I have any clues to what is the return syntax of this function and what is the method and keywords to search for such things, as well as a short little function that can maybe do that rotation and cropping? Since that looks like a quite common and simple thing to achieve.

Image recognition - finding similar images [duplicate]

This question already has answers here:
Checking images for similarity with OpenCV
(6 answers)
Closed 8 years ago.
Setup is as follows:
Database with paintings
robot that takes shots of paintings
I want to compare the shots the robot made with the images in our database.
Problem is that the shots won't be perfect. The painting will most likely be IN the shot, but the shot will also contain wall/other objects. The incidence of light will also cause problems. Therefore I want to be finding images in the database that are similar to a certain degree.
I've been reading up on PIL, scipy, openCV, machine learning.
Is there anything you guys can recommend for this problem?
Thanks in advance.
edit: I'm aware of the solutions presented at other posts. Such as: comparing histograms/template matching and feature matching. Comparing histograms is not going to cut it in my application. Neither will feature matching. As it is to much of a workload. Template matching might, however the angles at which the shots will be taken won't be any near perfect.
You could use the SSIM index. There is a python implementation in scikit-image package.
Your problem sounds more like an application of feature detection and matching. Given a shot captured by the robot, you extract features from it, and compare them against the list of features you have in your database (each image having a lot of features). You might want to look at SURF, or some other descriptor that does your job. OpenCV has very well documented implementations for many variants. Feature matching would be the last stage where you actually make a decision about a match or a non-match.
Note that all of this is really heavy on processing, so forget real-time.

How can I detect and track people using OpenCV?

I have a camera that will be stationary, pointed at an indoors area. People will walk past the camera, within about 5 meters of it. Using OpenCV, I want to detect individuals walking past - my ideal return is an array of detected individuals, with bounding rectangles.
I've looked at several of the built-in samples:
None of the Python samples really apply
The C blob tracking sample looks promising, but doesn't accept live video, which makes testing difficult. It's also the most complicated of the samples, making extracting the relevant knowledge and converting it to the Python API problematic.
The C 'motempl' sample also looks promising, in that it calculates a silhouette from subsequent video frames. Presumably I could then use that to find strongly connected components and extract individual blobs and their bounding boxes - but I'm still left trying to figure out a way to identify blobs found in subsequent frames as the same blob.
Is anyone able to provide guidance or samples for doing this - preferably in Python?
The latest SVN version of OpenCV contains an (undocumented) implementation of HOG-based pedestrian detection. It even comes with a pre-trained detector and a python wrapper. The basic usage is as follows:
from cv import *
storage = CreateMemStorage(0)
img = LoadImage(file) # or read from camera
found = list(HOGDetectMultiScale(img, storage, win_stride=(8,8),
padding=(32,32), scale=1.05, group_threshold=2))
So instead of tracking, you might just run the detector in each frame and use its output directly.
See src/cvaux/cvhog.cpp for the implementation and samples/python/peopledetect.py for a more complete python example (both in the OpenCV sources).
Nick,
What you are looking for is not people detection, but motion detection. If you tell us a lot more about what you are trying to solve/do, we can answer better.
Anyway, there are many ways to do motion detection depending on what you are going to do with the results. Simplest one would be differencing followed by thresholding while a complex one could be proper background modeling -> foreground subtraction -> morphological ops -> connected component analysis, followed by blob analysis if required. Download the opencv code and look in samples directory. You might see what you are looking for. Also, there is an Oreilly book on OCV.
Hope this helps,
Nand
This is clearly a non-trivial task. You'll have to look into scientific publications for inspiration (Google Scholar is your friend here). Here's a paper about human detection and tracking: Human tracking by fast mean shift mode seeking
This is similar to a project we did as part of a Computer Vision course, and I can tell you right now that it is a hard problem to get right.
You could use foreground/background segmentation, find all blobs and then decide that they are a person. The problem is that it will not work very well since people tend to go together, go past each other and so on, so a blob might very well consist of two persons and then you will see that blob splitting and merging as they walk along.
You will need some method of discriminating between multiple persons in one blob. This is not a problem I expect anyone being able to answer in a single SO-post.
My advice is to dive into the available research and see if you can find anything there. The problem is not unsolvavble considering that there exists products which do this: Autoliv has a product to detect pedestrians using an IR-camera on a car, and I have seen other products which deal with counting customers entering and exiting stores.

Categories