cvPyrDown() can somebody help me to modify this line - opencv

I am newbie to openCv, trying to analyze some code.
I know this line works fine and reduce destination by two but i want it to change to some other sizes, how can i change? Specifically "CV_GAUSSIAN_5x5"
cvPyrDown(frame, half_frame, CV_GAUSSIAN_5x5);

You cannot resize the image to any desired size by using pyrDown() because it will always resize your image by a factor of 2. Similar is the case with pyrUp().
If you want to resize your image to any desired size then you must use the resize()
cvResize(const CvArr* src, CvArr* dst, int interpolation=CV_INTER_LINEAR )
the detailed documentation about it is given here.

Related

Dart - How to get the Image height and width of a png file?

Is there a way in getting this sizes? Using command line. Thanks in advance. and can I ask something good tutorials in Dart?
I don't know a built-in feature that allows to do that except readying the content byte-wise and interpreting the values like explained for C++ in C++ How to get the Image size of a png file (in directory)
The image package seems to provide this functionality though. decodePng returns an image that has a width and height property.
The build-in function decodeImageFromList() can help you with that. Its callback contains an Image that includes the width and height.

resize image to specific height and width value using im4java?

I need to re-size image to any specific height and width value. But I'm not getting resized result. here is my code, please tell me either i'm doing something wrong or missing something.
IMOperation operationSmall = new IMOperation();
operationSmall.addImage("conf/error.png");
operationSmall.resize(300, 1000); // w*h
operationSmall.addImage("conf/errir_small.png");
Original Image size: 1280x960 px.
re-sized image size: 300x225
I tried to give different values, I'm only having issues in height.
their doc is not complete and no code example I find on internet except that using scale (it skip filtering) may solve this problem. but how to use scale in code I have not idea.
I don't read or understand java much, but at the command-line you need an exclamation mark to force ImageMagick to disregard aspect ratio and resize to exact/specific dimensions, like this:
convert -resize 300x200! image....
In the Java docs, there seems to be an option of adding a special 3rd parameter, so I guess you may need
operationSmall.resize(300,1000,'!');
or something similar... or maybe Java uses double quotes rather than the single quotes I suggested.

How to get rid of empty transparent areas in a PNG image so that it conforms to actual image size?

I have a series of images that I would look to loop through using iOS's [UIView startAnimating]. My trouble is that, when I exported the images, they all came standard in a 240x160 size, although only 50x50 contains the actual image, the rest being transparent parts that are just taking up space.
When I set the frame of the image automatically using image.size.width and image.size.height, iOS takes into images' original size of 240x160, so I am unable to get a frame that conforms to the actual parts of the image. I was wondering if there is a way using Illustrator or Photoshop, or any other graphics editing software for me to export the images based on their natural dimensions, and not a fixed dimension. Thanks!
I am a fan of vector graphics and thinks everything in the world should be vector ;-) so here is what you do in illustrator: file - document setup - edit artboards. Then click on the image, and the artboard should adjust to the exact size. You can of course have multiple artboards, or simply operate with one artboard and however-many images.

Calculate the height and width of image from the source file

I need to calculate the image width and height from the actual image file, so I'm reading the image with open file. so I have bunch of characters and numbers and everything that seems meaningless and they are presenting rgb information probably.
I just want to calculate the size of the image with the raw file information
I am programming in Erlang language but the code in any language will help as we are working with raw file as long as we don't use built-in libraries.
Thank you all in advance for help
I found the answer by going to details of each format,
So it works like this
JPG : you can find the width and height after the bytes "255,192,0,17,8" after that its the information for size
PNG : you can find it after "IHDR"
GIF : you can find it after "GIF89a"
there are information for more but this is the most common image types on internet
Thank you all for your time
I assume when you say 'raw' you mean you only have the pixel values.
In this case there isn't always a way to know the width and height.
Say you read 400 pixels. In this case a valid image side may be any whole factorization of 400, e.g. 1x400, 2x200, 4x100, 8x50, 20x20 etc. and transposed as well.
Not to mention the fact that many image formats include some padding for pixel rows that are not multiples of 4, 8 or 16...
The way it is coded in the image file depend on the image type, which hopefully is also coded in the image file. you can have a look at the question Getting Image size of JPEG from its binary for an example with JPEG coding.
If your data is unknown, use Octave and load the image. Then take a look at this page:
http://www.gnu.org/software/octave/doc/interpreter/Displaying-Images.html
for commands to display images. Hopefully with some manipulation it will work. This works for raw images, though there are specific decoders. Once you understand how the image is, you can write the equivalent C code.

Is Picture-in-Picture possible using OpenCV?

I would like to add a smaller image on top of a larger image (eventually for PiP on a video feed). I can do it by iterating through the relevant data property in the large image and add the pixels from the small image. But is there a simpler and neater way? I'm using EMGU.
My idea was to define an ROI in the large image of the same size as the small image. Set the Large image equal to the small image and then simply remove the ROI. Ie in pseudo code:
Large.ROI = rectangle defined by small image;
Large = Small;
Large.ROI = Rectangle.Empty;
However this doesn't work and the large image doesn't change. Any suggestions would be much appreciated.
Large image:
Small image:
Desired result:
If you using C++ API then the following code snippet should work:
cv::Mat big;
cv::Mat small;
// Define roi area (it has small image dimensions).
cv::Rect roi = cv::Rect(50,50, small.cols, small.rows);
// Take a sub-view of the large image
cv::Mat subView = big(roi);
// Copy contents of the small image to large
small.copyTo(subView);
Take care to not go out of dimensions of big image.
I don't know if this will help, i haven't used emgu. However this was how i was able to do image in image with opencv.
drawIntoArea(Mat &src, Mat &dst, int x, int y, int width, int height)
{
Mat scaledSrc;
// Destination image for the converted src image.
Mat convertedSrc(src.rows,src.cols,CV_8UC3, Scalar(0,0,255));
// Convert the src image into the correct destination image type
// Could also use MixChannels here.
// Expand to support range of image source types.
if (src.type() != dst.type())
{
cvtColor(src, convertedSrc, CV_GRAY2RGB);
}else{
src.copyTo(convertedSrc);
}
// Resize the converted source image to the desired target width.
resize(convertedSrc, scaledSrc,Size(width,height),1,1,INTER_AREA);
// create a region of interest in the destination image to copy the newly sized and converted source image into.
Mat ROI = dst(Rect(x, y, scaledSrc.cols, scaledSrc.rows));
scaledSrc.copyTo(ROI);
}
I have a lot of experience with EMGU. As far as I am aware the method your employing is the only direct way of display the sub-image data within your large image. You would likely have to refresh your larger image which would have the inherent effect of wiping your transferred data and copy the smaller image back over.
While a solution is possible I think the method is flawed. The required processing time will effect the display rate of any image in the larger viewing frame.
An improved method would be to add another control. Effectively you have your video feed window showing your larger image in the background and a smaller control on-top of this displaying your smaller image. Effectively you could have as many of these smaller controls as you like. You will in effect be displaying two images or video feeds in two different controls (e.g. image boxes). As you have the code to do so all you will have to do is ensure the order of which your controls are displayed.
I have assumed you are not programming the output to a Console Window. If you need any more help please feel free to ask.
As for the comments EMGU is written in C# and while appreciate your view on not calling EMGU OpenCV why should it not be tagged as an OpenCV orientated question. After all EMGU is simply OpenCV library with a c# wrapper. I have found many resources on OpenCV useful for EMGU and vice versa.
Cheers
Chris
Based on #BloodAxe's answer, using EMGU 3.4 the following works:
// Define roi area (it has small image dimensions).
var ROI = new System.Drawing.Rectangle(100, 500, 200, 200)
// Take a sub-view of the large image
Mat subView = new Mat(bigImage, ROI);
// Copy contents of the small image to large
small.CopyTo(subView);

Resources