Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am using OpenCV to make panorama.
But the result's dimensions aren't stable and whole stitching isn't stable.
Everytime I get different results.
Can somebody help me to understand what is the reason, or what part os the stitching pipeline isn't stable?
I am doing the most simple version of stitching, using stitch function.
Thank you.
As stitching relies on RANSAC algorithm and it has some degree of randomness (in fact RANSAC stands for Random sample consensus), its results are not stable.
I would pre-seed the random generator before any stitching operation to make the results repeatables.
http://www.cplusplus.com/reference/cstdlib/srand/
Without seeing your images this is a stab in the dark
Stitching consists of:
Finding keypoints
Matching keypoints by calculating distance between its corresponding descriptors
Some outlier detection process like RANSAC
Once you get matched keypoints, get homography. To get homography, you should at least have 8 pairs of matched keypoints. In
reality, you may require more, since some outliers may not get
removed.
The likelyhood is that somewhere in this process it is finding different keypoints in your image and calculating different distances and therefore different homography.
I would suggest trying the OpenCV Stitching example pictures and see if you get a similar response.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm using SVM since I need ML to train my classifier, and I saw on several papers on fire detection that they used SVM and logistic regression but since there is no logistic regression in 2.4.9 I'm planning on using SVM. I'm using opencv 2.4.9 since people said opencv 3 is buggy.
Im new to this so it will be helpful if we start from basic
I have prepared several fire and non-fire videos ready to be extracted into frames. I'm new to opencv and everything about classifiers. My question is what are the basics in training a classifier specifically SVM, What format do I need my images to be and how do I train them? Are there any good links for a tutorial? I found one in opencv documentation but it doesn't teach on training using image. What do I need in determining parameters and what are the parameters for? Thanks in advance
This is a conceptual question that calls for lots of papers and tutorials to explain. However, As it was explained in the comments I try to elaborate on feature extraction. Feature descriptors should be robust against scaling, translate and rotation. This robustness is literally referred to as invariant features. For instance, moments and its derivatives are one of the most famous type of invariant against rotation, scaling and translate. You may find the usage of Hu moments as explained in this paper.
Flame or fire detection is something different. The feature corresponds to flame can be extracted from fire's dynamic texture. For instance, fire has a special color texture that segregates it from the background. The conventional flame detectors make use of infrared sensors to detect a flame. In image processing, or RGB world, we can do the same by considering the nature of flame itself. Flame emits a significant portion of its energy through heat and infrared ray. So, one can expect a major portion of red channel to be devoted to flame. See the following image for example.
In the processed image, the red channel is converted to BW image by imposing a threshold. To be more clear, I have separated the 3 channels as below.
R: G: B:
It is evident the Red channel has more to say about the flame. Therefore, it can be concluded that the flame is where R channel has a portion of its information, then G and finally B channel. See this.
Your feature vector, then, will be a three dimensional vector about, for example, the contour of the flame in three RGB channels. SVM classifiers are now ready to be used. Sometimes, the video may contain flam-liked segments that should be avoided and they lead to false alarms otherwise. SVM, assists you to accept or reject a flame candidate. To train your support vector machine, collect some true flames and some images that may be misjudged by your feature extractor. Then, label them with positive and negative features. Finally, let opencv do the magic and train it. For more information about SVM, please watch this video by Patrick Winston, MIT on youtube.
UPDATE ----
As you are curious about creating feature vector, I brought to you the following example. Assume that R,G,B channels are finely segregated so as to one can call them statistically independent as the follow; This is not true in real images wherein R,G,B planes are not statistically independent.
Therefore, a point in the RGB image will have 3 representations in RGB channels. For instance, a flame will make 3 spots on all the R,G,B planes. The area of each spot, for example, is being traced here. Label the flame spot in RGB image as "A".
The representations of the area A were depicted above in R , G , B images. A_r , A_g , A_b denote the corresponding area of the area A on R,G,B planes, respectively.
Therefore, point A will be represented by a triplet (Ar,Ag,Ab) in xyz plane. SVM, now accepts this vector as input and decide if it signifies a real flame.
The areas, normalized format, is one of the many geometrical features that you can involve in decision making process. Other useful features of this kind are aspect ratios, moments and so on.
In a nutshell, you have to do the following:
1 - Find the flame-liked areas.
2 - Trace the candidate spot in all of the R,G,B planes.
3 - Extract the feature( I suggest moments) in every plane.
4 - Form the feature vector
5 - Feed the SVM with this vector
I hope you find this useful.
Yes right so your job now is to make a .txt file with data on each image that you gonna process.
The ones which are true will be denoted by +1 followeed with feature set and end it with a -1
and the ones which are false images of fires will start with -1 followed with feature sets and end it with -1 again before starting with feature set of next image
its gonna b a tedious job but I am sure ul manage that
and finally save that file with extension of .train and not .txt
so your training file name gonna be filename.train
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new in OpenCV and I want to know how can I identify the cars in a canny edged image
because I want to count the cars in the image based on their edges.
Here is the canny edged image
And here is the original image
The general problem of identifying dynamic objects on a given scene for whichever purposes, such as counting, may be tackled by the use of background subtraction.
The idea is to use one of the implementations of this technique that OpenCV provides, BackgroundSubtractorMOG for instance, to construct a background model for your scene, by providing every frame of a video stream for it to process. It will identify what features of the scene are most probably static, to construct a syntetic image of the most probable background, the parking lot without cars in your case. You would then subtract a given frame from this syntetic background and count the blobs which have a minimum size, i.e. are big enough to be vehicles.
The results are impresive and I particularly love this technique. On youtube you can check some examples, I suggest this one, which is very close to your particular case. This one here is also very interesting, because it displays the syntetic background image side by side with the current frame, so you can see how well it works. Pay close attention around 00:50 on this last video, you can see the car slowly appearing on the background image, because it stays on the same spot for too long.
Aren't humans good at spotting things? You even recognize the cars in the canny edge image, even though there is not a single wheel visible.
Anyway, the main reason why you're using canny edge detection is because you have a datastream of 10-100 Megapixels per second. You need to quickly find the interesting bits in there. And as your image shows, it works fantastically for that.
Now, to count actual cars in parking spaces, I would suggest a fixed setup procedure that identifies the potential parking spots. You don't want to count passing cars anyway. This step can be semi-automated by checking for parallel sets of lines in the canny image.
Once you've got those parking spots identified, it may be a good idea to define a mask. Use this mask to zero out the non-parking spot pixels. (Doing this before canny edge detection speeds up that process too, but obviously adds a false edge around the mask so you'd have to reapply the mask.)
Now it's really just checking if there's anything sufficiently big in a parking spot. You probably don't care if a motorbike is counted as a car anyway. To do so, use the canny edges to separate the car pixels from the surrounding parking lot pixels, and count if they differ (in color/brightness/texture/...)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have x,y,z 3D points in the array size of N x 3 dimensions. As they are scattered data points, I need to match into equally spaced grid data. The implementation in Matlab used TriScatteredInterp as shown in the link. I need to implement it in C++ and plot the data and save as png file. So I searched and found out that I should implement in PCL library. As I am not familiar with PCL, how can I approach that problem using PCL? Can I have any sample program?
Thanks
I don't understand your exact needs for the equaly spaced grid data. When looking at the matlab function I believe you would like to do the following:
1) Perform surface reconstruction on the scattered data points
In PCL you should be able to do this according to example:
Greedy Triangulation tutorial
2) Show the surface in a viewer
This step could be realized by using the VTK viewer. An example is shonw in:
VTK mesh viewing
3) Save the image of the viewer as a PNG file.
The last step could be realized using the VTKviewer also. An example can be found:
VTKviewer save as PNG example
Now I understand how TriScatteredInterp works in Matlab.
We have x,y,z points for N X 3 dimensions. All these points, we need to implement Delaunay triangles in C++. That is easy.
Then, for all your desired grid points x', y', please search the triangle in which your x',y' is located. Then do Barycentric interpolation in a triangle as shown in the link. You will get z' for these x',y'.
That is all what we need to do in C++ for TriScatteredInterp.
You will get a matrix of x',y',z', then I follow #Deepfreeze's idea for plotting using PCL. We can also use OpenGl for plotting.
It doesn't stop at Delaunay triangulation, still need to do interpolation.
I am trying to use two Gaussian mixtures with EM algorithm to estimate color distribution of a video frame. For that, I want to use two separate peaks in the color distribution as the two Gaussian means to facilitate the EM calculation. I have several difficulties with the implementation of these in OpenCV.
My first question is: how can I determine the two peaks? I've searched about peak estimation in OpenCV, but still couldn't find any seperate function. So I am going to determine two regions, then find their maximum values as peaks. Is this way correct?
My second question is: how to perform Gaussian mixture model with EM in OpenCV? As far as I know, the "cv::EM::predict" function could give me the index of the most probable mixture component. But I have difficulties with training EM. I've searched and found some other codes, but finding the correct parameters is too much difficult for. Could someone provide me any example code for this? Thank you in advance.
#ederman, try {OpenCV library location}\opencv\samples\cpp\em.cpp instead of the web link. I think the sample code in the link is out of date now. I have successfully compiled the sample code in OpenCV 2.3.1. It shouldn't be a problem for 2.4.2.
Good luck:)
My first question is: how can I determine the two peaks?
I would iterate through the range of sample values possible, and test when the does EM.predict(sample)[0] peaks.
I am currently working on a data visualization project.My aim is to produce contour lines ,in other words iso-lines, from gridded data.Data can be temperature, weather data or any kind of other environmental parameters but only condition is it must be regularly spaced.
I searched in internet , however i could not find a good algorithm, pseudo-code or source code for producing contour lines from grids.
Does anybody knows a library, source code or an algorithm for producing contour lines from gridded data?
it will be good if your suggestion has a good run time performance, i don't want to wait my users so much :)
Edit: thanks for response but isolines have some constrains like they should not intersects
so just generating bezier curves does not accomplish my goal.
See this question: How to approximate a vector contour from an elevation raster?
It's a near duplicate, but uses quite different terminology. You'll find that cartography and computer graphics solve many of the same problems, but use different terminology for them.
there's some reasonably good contouring available in GNUplot - if you're able to use GPL code that may help.
If your data is placed at regular intervals, this can be done fairly easily (assuming I understand your problem correctly). First you need to determine at what interval you want your contours. Next create the grid you are going to use to store the contour information (i'm assuming just a simple on/off or elevation at this contour level type of data), which should be one interval smaller than the source data.
Now the trick here is to offset the 2 grids by 1/2 an interval (won't actually show up in code like this, but its the concept I'm dealing with here) and compare the 4 coordinates surrounding the current point in the contour data grid you are calculating. If any of the 4 points are in a different interval range, then that 'pixel' in the contour grid should be set to true (or the value of the contour range being crossed).
With this method, there will be a problem when the interval is too fine which will cause several contours to overlap onto each other.
As the link from Paul Tomblin suggests, Bezier curves (which are a subset of B-splines) are a ripe solution for your problem. If runtime performance is an issue, Bezier curves have the added benefit of being constructable via the very fast de Casteljau algorithm, instead of drawing them according to the parametric equations. On the off chance you're working with DirectX, it has a library function for the de Casteljau, but it should not be challenging to brew one yourself using the 1001 web pages that describe it.