Convert a PXCImage into an OpenCV Mat (PIXEL_FORMAT_YUY2) - c++

I'm working on the Intel's RealSense SDK and I have to convert it into an OpenCV format.
I saw this solution in the forum (Convert a PXCImage into an OpenCV Mat) but for the "PIXEL_FORMAT_YUY2" type doesn't work that code.
Anyone knows how to change it?
Thanks in advance

I don't know the Intel RealSense SDK as I have only used the librealsense API.
The documentation for the Intel RealSense SDK shoud be here.
I don't know how it works with the SDK but with librealsense you can select directly the appropriate color format (for OpenCV mat it should be bgr8).
If you don't have this option with the SDK, you can see here how librealsense unpack yuy2 format.
Or maybe you can try to copy the data directly to a mat (you will have to figure out the good value for cvDataType and the good value for cvDataWidth) and then use cvtColor() with the appropriate conversion if you want to be able to access to the pixel values as a RGB triplet?
Hope it helps.

Related

Unexpected camera calibration results with OpenCV over JPEG images and EXIF orientation

I am exploiting OpenCV to calibrate a set of images. I am using the standard function cv::calibrateCamera offered by OpenCV, nothing special here. The images are in JPEG format, and the EXIF Orientation flag is set (and it can be != 1).
I have noticed that if the images are not all top-left oriented (Orientation == 1) the calibration result is wrong, usually resulting in a very high RMS error. On the contrary, if I manually correct the orientation (using mogrify or exiftool, for instance), the result is as expected.
Have you ever encountered this kind of behavior? Can you please explain me why this is happening?
As a side note, I am using OpenCV 3.1 on a Mac OSX El Capitan, installed via Homebrew. Code is in C++.
are you using imread or cvLoadImage? imread for opencv 3.1 seems to handle exif correctly, but cvLoadImage not. See the following opencv bug https://github.com/opencv/opencv/issues/6673

OpenCV to FlyCapture2 Image

I have an bumblebee2 and I'm using the flycapture SDK to capture the incoming images. I then convert the left flycapture2 image to an openCV format so I can do some basic manipulations to it. Then I'd like to feed it back into the Flycapture SDK but I cant seem to figure out how. To convert from Flycapture to OpenCV I do the following:
FlyCapture2::Image cf2Img;
grabbedImage.Convert(FlyCapture2::PIXEL_FORMAT_BGR, &cf2Img );
unsigned int rowBytes = (double)cf2Img.GetReceivedDataSize()/(double)cf2Img.GetRows();
cv::Mat cvImage = cv::Mat( cf2Img.GetRows(), cf2Img.GetCols(), CV_8UC3, cf2Img.GetData(), rowBytes );
I then do my manipulations (thresholding/contour detections/background removal etc), I'd then like to feed this image back into Flycapture. My attempts at converting it back haven't worked.
Does anyone have any code they have used before to take an OpenCV format back to Flycapture?
I work for Point Grey and I'll try to help here. Please note though you can contact us directly via our support site at ptgrey.com/support/ and we can help you out as well.
Looking at the code you attached and looking at the openCV source, when you make the cvImage, you are just reassigning the pointer to the data, you are not making an actual copy of the data.
So as long as the size of the data stays the same (ie. you keep it at 24 bits per pixel), any changes you make to the openCV image should be reflected in the flycapture (cf2Img) data and be able to save properly.
If you can explain the problems you are having trying to move back to a flycapture image, or send us the source code of how you are doing that, we can help you further.
To summarize, I expect any manipulations you do to the cvImage after the code you have provided should just be reflected in cf2Img without the need to convert back, assuming you are not changing the bit depth of the image.
I hope that helps, but please let me know if I can help clarify anything or if you can provide an example of the failure to convert back to fc2.
Thank you,
Point Grey Support

Imaging library to display yuv data in C++ and Qt

I was wondering is there any C++ imaging libraries so that I can take a yuv file and display it, I will be able to pass the resolution of the file and Ycbcr info(usually at 4:2:2) I need this to turn the yuv into jpegs if possible or to display it in rgb mode to be built on a QPixmap. If anyone could point me in the right direction I'd be most grateful.
I just looked around, did you tried the following ?
http://code.google.com/p/yuvtoolkit
http://code.google.com/p/yuvplayer

OpenCV 2.3 C++ basic image processing

What is the best way to open an image, manually manipulate the pixels as floats, normalize the pixels back to 8bit int values (0-255) and save the new image.
I found deferment codes use different variable types and commands, should i use Iplimage or mat, imread, and so on...
i would really appreciate a code example
Thanks!
You may want to look at the tutorial section provided in the OpenCV docs: OpenCV Tutorials. Especially "Introduction to OpenCV" and "core module. The Core Functionality" are the chapters you should be most interested in.
Refer here. This gives the basic code sample.

Transform OpenCV image data type to Devil image format and vice-versa

I want to use a CUDA-enabled SIFT library but I am using the OpenCV driver to get images from the webcam? The Cuda library is using the Devil Library for image data types.
Should I transform the images from OpenCV data types to Devil? Or Should I use another method for getting images from the webcam[devil compatible data types]?
I am not familiar with the DeviL but from the manual it states that it supports the following formats:
IL_COLOUR_INDEX
IL_RGB
IL_RGBA
IL_BGR
IL_BGRA
IL_LUMINANCE
of varying bit depths.
When loading images, OpenCV also supports most of these image types and bit depths and conversion between them is pretty straightforward (see the convertTo() function in the openCV documentation) . Using a webcam may be more complex.
It is difficult to answer your question directly without knowing the interface of the specific library. If the library accepts a devil image in a specific form, then it is likely you will have to give it in that form. OpenCV will likely be able to output data in the required form; if not, you may have to write code to transform it yourself.