What should I do for multiple histograms? - opencv

I'm working with openCV and I'm a newbie in this field. I'm researching about Camshift. I want to extend this method by using multiple histograms. It means when tracking an object has many than one apperance (ex: rubik cube with six apperance), if we use only one histogram, Camshift will most likely fail.
I know calcHist function in openCV (http://docs.opencv.org/modules/imgproc/doc/histograms.html#calchist) has a parameter is "accumulate", but I don't know how to use and when to use (apply for camshiftdemo.cpp in opencv samples folder). This function can help me solve this problem? Or I have to use difference solution?
I have an idea, that is: create an array histogram for object, for every appearance condition that strongly varies in color, we pre-compute and store all to this array. But when we compute new histogram? It means that the pre-condition to start compute new histogram is what?
And what happend if I have to track multiple object has same color?
Everybody please help me. Thank you so much!

Related

OpenCV Background Model Component Extraction

I am working with the BackgroundSubtractorMOG2 class in OpenCV (Python), and am trying to extract the individual components of the background model. As I understand it, each pixel will be modeled by the mixture of a varying number of gaussian distributions, each defined by a mean and variance. So, how can I determine what all of these components (means and variances) are after feeding the background subtractor a given number of frames?
The documentation here:
https://docs.opencv.org/3.4.3/d7/d7b/classcv_1_1BackgroundSubtractorMOG2.html#adbb1d295befaff88a54a929e50aaf879
Does not seem to discuss doing this.
This information must be contained somewhere in the background subtractor object. Does anyone know how to get to it?
Thanks!
Edit: A little more searching has led me to believe that the cv2.Algorithm class is required to read the parameters from the BackgroundSubtractorMOG2 object. I think the two questions posed here:
http://answers.opencv.org/question/28008/how-to-derive-from-algorithm/
Reading algorithm parameters from file in OpenCV
are similar to what I am asking, but I am unable to interpret the answers. I thought the solution would be something along the lines of:
Parameters = cv2.Algorithm.read('name_of_backgroundsubtractorMOG2_object')
but this returns an error of: 'Required argument 'fn' (pos 1) not found'
Edit 2: Unfortunately I think this question has been answered here:
Save opencv BackgroundSubtractorMOG to file?
Short answer: It cannot be done! Sad!

Change in two 3D models

I'm trying to think of the best way to conduct some sort of analysis between two 3D models of the same object.
The first scan is of the original item and the second scan is after it has been put under some load x.
An example would be trying to find the difference between two types of metal.
I would like to be able to scan the initial metal cylinder, apply a measured load, scan it again, and then finally apply some sort of algorithm to compare the difference.
Is it possible to do this efficiently (maybe using Mablab) over say 50 - 100 items for an object around 5inch^3?
I am assuming I will need to work out some sort of utility function as the total mass should be the same?
Would machine learning be beneficial in this case?
Any suggestions or direction would be amazing.
Thank you :)
EDIT: The scan files are coming through as '.stl'

error detection on food packaging -using Open Cv

I am trying to determine when a food packaging have error or not error. Example
the logo " McDonald's " have error misprints or not, as the wrong label, wrong color..( i can not post picture )
What should I do, please help me!!
It's not a trivial task by any stretch of the imagination. Two images of the same identical object will always be different according to lightning conditions, perspective, shooting angle, etc.
Basically you need to:
1. Process the 2 images into "digested" data - dominant color, shapes, etcw
2. Design and run your own similarity algorithm between the 2 objects
You may want to look at Feature detectors in OpenCV: Surf, SIFT, etc.
Along a result I just found your question, so I think I come too late.
If not I think your problem car easily be resolved, it exists since years and is called Sikuli .
While it's for testing purposes, I have been using it in the same way as you need : compare a reference and a production image. Based on OpenCV it does it very well.

Can someone explain the parameters of OpenCV Stitcher?

I'm trying to reduce the calculation time of my stitching algorithm. I got some images which I want to stitch in a defined order but it seems like cv::stitcher.stitch() function tries to stitch every image with every other image.
I feel like I might find the solution in the parameters of OpenCV Stitcher. If not maybe I have to modify the function or try something else to reduce calculation time. But since I'm pretty much a beginner, I don't know how. I know that using GPU might be a possibility but I just don't get CUDA running on Ubuntu at the moment.
It would be great if you could give me some advice!
Parameters for OpenCV Stitcher module:
Stitcher Stitcher::createDefault(bool try_use_gpu) {
Stitcher stitcher;
stitcher.setRegistrationResol(0.6);
stitcher.setSeamEstimationResol(0.1);
stitcher.setCompositingResol(ORIG_RESOL);
stitcher.setPanoConfidenceThresh(1);
stitcher.setWaveCorrection(true);
stitcher.setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ);
stitcher.setFeaturesMatcher(new detail::BestOf2NearestMatcher(try_use_gpu));
stitcher.setBundleAdjuster(new detail::BundleAdjusterRay());
from stitcher.cpp:
https://code.ros.org/trac/opencv/browser/trunk/opencv/modules/stitching/src/stitcher.cpp?rev=7244
I want to stitch in a defined order but it seems like
cv::stitcher.stitch() function tries to stitch every image with every
other image.
cv::stitcher does not have a parameter to fulfil your requirement.
However, in the stitching_detailed.cpp sample you have the --rangewidth parameter. By setting it to 1, the algorithm will only consider adjacent image pairs (e.g. for pair 1-2 matches would be computed but not for pair 1-3)

OpenCV: how to access one contour in O(1) after call cvFindContours()?

I'm using OpenCV to compare two blobs in two images. Suppose I've known
a pair of blobs that are likely to be similar, and I know their indices
in the contour arrays (generated by cvFindContours()), how can I get
access to one contour in a constant time?
The most cumbersome way is to use the link operation (contours=contours->h_next) multiple times, but I wonder if there is a faster way to retrieve one contour in an array.
I use CV_RETR_EXTERNAL and CV_CHAIN_APPROX_NONE in calling cvFindContours().
Thanks!
-J.C.
I think the function cvGetSeqElem does what you want. Quoting the OpenCV docs: "The function has O(1) time complexity assuming that the number of blocks is much smaller than the number of elements." I suppose "blocks" means "contours" in this context.
Also, take a look at cvCvtSeqToArray (link), which copies a sequence to one continuous block of memory.

Resources