I'm working with the OpenCV library in XCode and doing a colour tracking application that draws lines from one point to the next. I was wondering if it's possible to put the output not as the video but as a white background.
So instead of
cvShowImage("video",frame);
Is there a function that would show (backgroundcolour, frame)?
edit:
I've added this code but since canvas is not an image it won't let me write on to it instead of frame.
cv::Mat canvas(320, 240, CV_8UC3, Scalar(255,255,255));
IplImage* imgYellowThresh1 = GetThresholdedImage1(canvas);
cvAdd(&canvas,imgScribble,&canvas);
cvShowImage("video",&canvas);
So the erro is on the GetThresholdedImage1 saying "no matching function for call to GetThresholdedImage1"
No, not it such a simple way you proposed. The solution would be to create separate Mat and draw the lines on it.
cv::Mat canvas(rows, cols, CV_8U3C, Scalar(255,255,255)); //set size, type and fill color
You would prepare this mat an the begining of code, and then use the draw functions on it. So instead of drawing the lines on frame you would draw on canvas.
EDIT:
There was slight misconception. The problem is you are using old C API. To learn about the latest C++ API, follow this tutorials:
http://docs.opencv.org/doc/tutorials/tutorials.html
Related
I'm working currently with EmguCV and I need empty Mat. But apparently when I create it, the new Mat has sometimes some random values which I do not want.
I'm creating it like that:
Mat mask =new Mat(mainImg.Size,Emgu.CV.CvEnum.DepthType.Cv8U,1);
And when I display the 'mask' it looks like that:
It should be completely black but as you can see there is some trash which cause me trouble in reading the mat.
Does anyone know why it is like that? Maybe is there a clever way to clear the Mat?
Thanks in advance!
To create an empty Mat just use the code below.
Mat img = new Mat();
If you want to make it a specific size, use the following code. In your question above, you were choosing a depth type of 8U, which might be contributing to your low quality of an image. Here I choose a depth type of 32F, which should increase the quality of the new mask image. I also added 3 channels instead of 1, so you can have full access to the Bgr color space.
Mat mask = new Mat(500, 500, DepthType.Cv32F, 3);
Mat objects are great because you don't need to specify the size or depth of the image beforhand. Simmilarly, if you want to use an Image instead, you can use the code below.
Image<Bgr, byte> img = new Image<Bgr, byte>(500, 500);
You will need to add some dependencies, but this is the easiest and my preferred way of doing it.
Using opencv, we can display text over an image. The standard method is
cv2.putText(img, "my_text", (x, y), font, 1.0, (255, 255, 255), 0)
But I want to display a small icon image followed by text (in this case "my_text").
I could overlay an image over the image in this way:
icon_img = cv2.imread("icon.png")
icon_img1= cv2.resize(icon_img, (20,20))
x_offset=y_offset=5
img[y_offset:y_offset+icon_img1.shape[0], x_offset:x_offset+icon_img1.shape[1]] = icon_img1
But I want the icon to shift along with the display text.
An icon might look like this
Thank you!
This isn't really possible in opencv.
Opencv has no concept of z-layers in its basic GUI, so you would be responsible for setting the location of every element in the image. Opencv's GUI was not really developed to be the interface for a full fledged application, but more for testing and development purposes. If you really want a full fledged GUI I recommend Qt or wxPython.
However, for this very basic problem, what you could do is something like
icon_img = cv2.imread("icon.png")
icon_img1= cv2.resize(icon_img, (20,20))
x_offset=y_offset=5
img[y_offset:y_offset+icon_img1.shape[0], x_offset:x_offset+icon_img1.shape[1]] = icon_img1
cv2.putText(img, "my_text", (x_offset+icon_img1.shape[1], y_offset+icon_img1.shape[0]), font, 1.0, (255, 255, 255), 0)
This would shift the text to be placed after the image, right at the bottom right corner of the image
I am not certain I understand what you are doing, but I gather you want to place an icon with some related text at various positions around the frame over a video, yes? And I assume you want the text to stay in the same place relative to the icon, yes?
If so, I would create a small "piece of canvas" (i.e. a Mat) just big enough for the icon and the text and place them both on it.
Then, as each frame of video arrives, create an ROI in the video frame, and use copyTo() to copy that little piece of canvas ontop of the video frame:
// define image ROI at bottom-right of video frame
cv::Mat imageROI(frame, cv::Rect(frame.cols-canvas.cols,
frame.rows-canvas.rows,
canvas.cols,canvas.rows));
// insert icon canvas
canvas.copyTo(imageROI);
Using cvCopy I get the object without background (in webcam stream). I want to make a transparent with removed background, because I need to play another video in the background.
How can Ido this?
You can follow these steps:
1.) You said you have the object without the background. Hence it will be straightforward to achieve a binary mat for the object (Convert the image into Grayscale and then threshold it). Let's call this Binary mask as objectBinMask
2.) Suppose each frame of your video is called vidFrame, in that case you can use the object mask to paste the object on the video frame, as so:
vidFrame.copyTo(outputFrame,objectBinMask);
here outputFrame should have the required object on each frame of the video.
copyTo is a method available in C++, you can equivalently use cvCopy for your C code.
I use the OpenCV for show in a new windows the left and right image from a stereo camera. Now I want to see the same thing on the Oculus Rift but when I connect the Oculus the image doesn't became in the Characteristic Circled image suitable with the lens inside the Oculus...
I need to process by myself the image ? It's not Automatic?
This is the code for show the windows:
cap >> frame; //cap= camera 1 & cap2=camera 2
cap.read(frame);
sz1 = frame.size();
//second camera
cap2 >> frame2;
cap2.read(frame2);
sz2 = frame2.size();
cv::Mat bothFrames(sz2.height, sz2.width + sz1.width, CV_8UC3);
// Move right boundary to the left.
bothFrames.adjustROI(0, 0, 0, -sz1.width);
frame2.copyTo(bothFrames);
// Move the left boundary to the right, right boundary to the right.
bothFrames.adjustROI(0, 0, -sz2.width, sz1.width);
frame.copyTo(bothFrames);
// restore original ROI.
bothFrames.adjustROI(0, 0, sz2.width, 0);
cv::imencode(".jpg", bothFrames, buf, params);
I have another problem. I'm trying to add the OVR Library to my code but I have the error "System Ambibuous Symbol" because some class inside the OVR Library used the same namaspace... This error arise when I add the
#include "OVR.h"
using namespace OVR;
-.-"
The SDK is meant to perform lens distortion correction, chromatic aberration correction (different refractive indices for different color light causes color fringing in image without correction), time warp, and possibly other corrections in the future. Unless you have a heavy weight graphics pipeline that you're hand optimizing, it's best to use the SDK rendering option.
You can learn about the SDK and different kinds of correction here:
http://static.oculusvr.com/sdk-downloads/documents/Oculus_SDK_Overview.pdf
It also explains how the distortion corrections are applied. The SDK is open source so you could also just read the source for a more thorough understanding.
To fix your namespace issue, just don't switch to the OVR namespace! Every time you refer to something from the OVR namespace, prefix it with OVR:: - e.g, OVR::Math - this is, after all, the whole point of namespaces :p
Im working on a painting app which has a tool to brush similar to a painting brush. I've implemented so far through cocos2d, a format like the image
. But my client wants clear edged texture as the image Also the color of the former image is some what blurring indeed. How I can reduce blurring of the sprite image? The image I am using as a texture is the image. Im using a code derived from the Cocos2d RenderTextureTest.
Also, the blend function Im using like in the below code
[brush setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE}];
[brush.texture setAliasTexParameters];
where, brush is my sprite with the above mentioned texture.
Is there any other way to get the sharp edges as in the later image? Or how I can make the image stop blurring? I am struggling it for last few months. Please some experts look into this and help me.