Finding YUV file format in Cocoa - cocoa

I got a raw YUV file format all I know at this point is that the clip has a resolution of 176x144.
the Y pla is 176x144=25344 bytes, and the UV plan is half of that. Now, I did some readings about YUV, and there are different formats corresponding to different ways how the Y & US planes are stored.
Now, how can perform some sort of check in Cocoa to find the raw YUV file format. Is there a file header in the YUV frame where I can extract some information?
Thanks in advance to everyone

Unfortunately, if it's just a raw YUV stream, it will just be the data for the frames written to disk, one after another. There probably won't be a header that indicates what specific format is being used.
It sounds like you have determined that it's a YUV 4:2:2 stream, so you just need to determine the interleaving order (the most common possibilities are listed here). In response to your previous question, I posted a function which converts a frame from the UYVY (Y422) YUV format to the 2VUY format used by Apple's YUV OpenGL extension. Your best bet may be to try that out and see how the images look, then modify the interleaving format until the colors and image clears up.

Related

Does AVFrame store AV_PIX_FMT_YUV420P data as YVU?

I am decoding raw H.265 data using avcodec_decode_video2 api. When I examine the resulting instance pictYUV of type AVFrame, I see that pictYUV->format is AV_PIX_FMT_YUV420P and pictYUV->data[0] points to Y-plane. Both of these are expected. However, it appears pictYUV->data[1] seem to contain V-plane data and pictYUV->data[2]seem to contain U-plane data. My intuition was that pictYUV->data would store YUV planes in that order and not YVU planes. Wondering if the data is always ordered as YVU or is there some flag I failed to look at. Regards.
AV_PIX_FMT_YUV420P is planar YUV format (see P at the end of its name), so Y, U, and V are stored separated. There are also YUV formats with interleaved YUV format.
If you are getting the data from an IP camera, it is normal to get planar format.

To detect the image/frame in the video

I was given two inputs one is an image (image from .mp4 video file)and the other one is video(mostly in .ts format). Mostly the video is lossy encoding. I need to find the image in the video. Here I can't compare the raw frames of video and image as they are different in encoding . To my knowledge, I need to find same alike image/frame in the video with respect to image. Is there any tools/api to find the image in the video.
Detect features and try to establish a homography.
Then pick the frame with the most homography inliers (the cv::findHomography function has an output parameter named mask)

Match two images in different formats

I'm working on a software project in which I have to compare a set of 'input' images against another 'source' set of images and find out if there is a match between any of them. The source images cannot be edited/modified in any way; the input images can be scaled/cropped in order to find a match. The images can be in BMP,JPEG,GIF,PNG,TIFF of any dimensions.
A constraint: I'm not allowed to use any external libraries. ImageMagick is an exception and can be used.
I intend to use Java/Python. The software is purely command-line based.
I was reading on SO and some common image comparing algorithms. I'm planning to take 2 approaches.
1. I could use Histograms/buckets to find out the RGB values of the 2 images being compared.
2. Use SIFT/SURF to fin keypoint descriptors and find the euclidean distance between them and output the result based on the resultant distance.
The 2 images in comparison can be in different formats. An intuitive thought is that before analysis/comparison, the 2 images must be converted to a common format.I reasoned that the image should be converted to the one with lesser quality e.g. if the 2 input images are BMP and JPEG, convert the BMP to JPEG. This can be thought of as a pre-processing step.
My question:
Is image conversion to a common format required? Can 2 images of different formats be compared? IF they have to be converted before comparison, is my assumption of comparing from higher quality(BMP) to lower(JPEG) correct? It'd also be helpful if someone can suggest some algorithms for image conversion.
EDIT
A match is said to be found if the pattern image is found in the source image.
Say for example the source image consists of a football field with one player. If the pattern image contains the player EXACTLY as he is in the source image, then its a match.
No, conversion to a common format on disk is not required, and likely not helpful. If you extract feature descriptors from an image (SIFT/SURF, for example), it matters much less how the original images were stored on disk. The feature descriptors should be invariant to small compression artifacts.
A bit more...
Suppose you have a BMP that is an image of object X in your source dataset.
Then, in your input/query dataset, you have another image of object X, but it has been saved as a JPEG.
You have no idea how what noise was introduced in the encoding process that produced either of these images. There is lighting differences, atmospheric effects, lens effects, sensor noise, tone-mapping, gammut-mapping. Some of these vary from image to image, others vary from camera to camera. All this is done before the image even gets saved to storage in the camera. Yes, there are also JPEG compression artifacts, but to assume the BMP is "higher" quality and then degrade it through JPEG compression will not help. Perhaps the BMP has even gone through JPEG compression before being saved as a BMP.

How to create RAW image?

I'm building one part of H264 encoder. For testing system, I need to created input image for encoding. We have a programme for read image to RAM file format to use.
My question is how to create a RAW file: bitmap or tiff (I don't want to use compressed format link JPEG)? I googled and recognize alot of raw file type. So what type i should use and how to create? . I think i will use C/C++ or Matlab to create raw file.
P/S: my need format is : YUV ( or Y Cb Cr) 4:2:0 and 8 bit colour deepth
The easiest raw format is just a stream of numbers, representing the pixels. Each raw format can be associated with metadata such as:
width, heigth
width / image row (ie. gstreamer & x-window align each row to dword boundaries)
bits per pixel
byte format / endianness (if 16 bits per pixel or more)
number of image channels
color system HSV, RGB, Bayer, YUV
order of channels, e.g. RGBA, ABGR, GBR
planar vs. packed (or FOURCC code)
or this metadata can be just an internal specification...
I believe one of the easiest approaches (after of course a steep learning curve :) is to use e.g. gstreamer, where you can use existing file/stream sources that read data from camera, file, pre-existing jpeg etc. and pass those raw streams inside a defined pipeline. One useful element is a filesink, which would simply write a single or few successive raw data frames to your filesystem. The gstreamer infrastructure has possibly hundreds of converters and filters, btw. including h264 encoder...
I would bet that if you just dump your memory, that output will conform already to some FOURCC -format (also recognized by gstreamer).

simple image format for encoding geometry data and decoding in HTML5 Canvas

I'm trying to encode geometric data in an image file to decode in-browser using Canvas. Beyond what I learned from reading the about the GIF, PNG and BMP formats today, I don't know much about image files (or binary files in general! I grok binary math conversions, but I've never had to interrogate or write binary data without something abstracting it for me).
This Mozilla tutorial (https://developer.mozilla.org/En/HTML/Canvas/Pixel_manipulation_with_canvas) indicates that Canvas reads the image as an array of 8-bit values, every four representing RGBA.
This leads me to believe I want to encode my data as an array of 8-bit values, and put it between an image header and an image footer.
What's the simplest way to do this?

Resources