OpenCV 2.4 copyTo function - opencv

Using OpenCV 2.4.2 C/C++
I am trying to use the copyTo function to add a binary CV_8UC1 image to a RGB CV_8UC3 image. However, it seems to crash the program whenever I do this. I'm assuming that the difference in the number of channels doesn't allow me to add them. Is there some type of conversion that can allow me to use this copyTo function? I'm stitching a camera feed with its thresholded image side by side.
I'm using src.copyTo(dst(Rect(x,y,w,h))); as the copying code, and inRange(src,Scalar(#,#,#),Scalar(#,#,#),dst) as the thresholding operation.
I've tried to use the convertTo function but not having much luck with it. Can anyone give some advice?
Thanks

You should use cv::cvtColor function, which can convert from one color space to another. Look here for details.

Related

Bilinear interpolation in Swift

I am currently working on implementing spectrogram and the input to it are output from FFT. The results which I am getting is very pixelated. To make the output more smooth, I need to implement bilinear interpolation.
Is there any library or API readily available for it?
I found a function samplingLinear() in CoreImage which samples an image using bilinear interpolation. However, I need to interpolate the FFT data instead of an image.
Any help will be greatly appreciated.Spectrogram_Sample
Thanks.
Assuming you're displaying the data via OpenGL/CoreAnimation/UIImageView, you should do the interpolation there.
E.g. if you're displaying the data via a CALayer, you can set the magnificationFilter to kCAFilterLinear. If you're using OpenGL, you can set GL_TEXTURE_MAG_FILTER to GL_LINEAR.

OpenCV Image Matching

I have two images from a stereo camera of the same scene, but few different perspectives (imgLeft and imgRight).
Now, I want to find a ROI (red rectangle in the image below) of the right image in the left one. I need to do this very fast, because I'm doing this in a video. How can I do this? I do not have the nonfree of OpenCV; but I have CUDA installed.
imgRight:
imgLeft:
This should be your friend http://docs.opencv.org/2.4/modules/video/doc/motion_analysis_and_object_tracking.html#calcopticalflowpyrlk
All you need to do is to find feature points inside this rectangle and pass them to the cv::calcopticalflowpyrlk to get there peers in the second image. You may need to make some filtering for the points to make sure that the tracking was perfect like for example pass them to cv::findHomography using CV_RANSAC flag and check the mask output.
The operation is fast and real-time. There is also a CUDA version of this method.

OpenCV Histogram Backprojection Alternative

I start with creating an initial mask of an object in an image. Using this mask, a histogram is created which is then used to process subsequent images.
I use the calcBackProject function to find pixels in the image that belong to the histogram. The problem I am having is that too much of the image is being accepted because certain objects are similar to the color of the initial object. Is there any alternative to calcBackProject? In my application, I can't afford to get objects that do not belong. All of this assumes that I have a perfect initial mask.
There are many ways to track an object, and it can be very difficult. Within OpenCV you may want to try the meanshift/camshift tracker to see if these are any better. If not then you may have to stray out of the opencv world and try tracking-learning-detection frameworks.
Meanshift/Camshift/etc in OpenCV
http://docs.opencv.org/modules/video/doc/video.html
http://docs.opencv.org/trunk/doc/py_tutorials/py_video/py_meanshift/py_meanshift.html
Tracking-Learning-Detection in C++:
STRUCK: http://www.samhare.net/research/struck (uses opencv)
Tracking-Learning-Detection in Matlab:
Preditor: http://personal.ee.surrey.ac.uk/Personal/Z.Kalal/tld.html

SimpleBlobDetection Code

Hi I am a pure novice in image processing especially with openCV. I want to write a program on blob detection that takes an image as an input and returns the color and centroid of the blob. My image consists purely of regular polygons in a black background. For eg. my image might consist of a green triangle(equilateral) or a red square in a black background. I want to use the simpleBlobDetection class in opencv and its 'detect' function for this purpose. Since I'm a novice a full program will be a lot of help to me.
I suggest you to use the complementary openCV library cvblob. It has an example to automatically obtain blobs in an image, centroid, contour, etc.
Here is the source code, i tried it in OSX and works really fine.
Link: https://code.google.com/p/cvblob/

Change the brightness/contrast of an image in EmguCV

I have a program that will load an image from the hard disk. The program is written using emgu cv and the image is a Bgr image. I want to allow the user to increase/decrease the brightness/contrast of the image. How can I do this? Some sample code would be appreciated (because I am still a newbie). Thanks.
It depends on your image adjustment requirements.
You can start using some basic techniques already wrapped in emguCV such as histogram equalization and gamma correction. You can also combine them to achieve better result.
Image<Bgr, byte> inputImage;
inputImage._EqualizeHist();
inputImage._GammaCorrect(1.8d);

Resources