Use the system/C language interface to read YUV Image Sequences

Source: Internet
Author: User

System OpenGL code

'Define pic_w 176 // image width' define pic_h 144 // Image Height 'define frame 300 // total number of frames 'define h_clk 5 // half-cycle typedef byte unsigned ubyte_t; // read a frame image, num indicates the first frame, read pixels are stored in the array frame import "DPI-C" function int read_yuv (inout ubyte_t frame [], input int num); program rdic rd_yuv int I _frame = 0; // indicates the number of frames to read, ubyte_t frame ['pic _ H] ['pic _ w] From frame 1; // an array containing pixels initial begin bit CLK; // read reference frame A1: assert (read_yuv (frame, I _frame) = 1) else $ error ("read frame failed! "); Fork forever # 'H _ CLK =! CLK; forever @ (posedge CLK) Begin // process #100 + + I _frame; // process A2: assert (read_yuv (frame, I _frame) = 1) else $ error ("read frame failed! "); End join_none endendprogram

C language code. Only brightness and color are read.

# Include <math. h> # include <stdio. h> # include <stdlib. h> # include <malloc. h> # include <string. h> # include <svdpi. h> # define pic_p "f :\\ sequence \ YUV \ foreman_qcif.yuv" // image path int read_yuv (const svopenarrayhandle pix_array, const int I _frame) {int width, height; uint8_t * ADDR; file * FP; width = svsize (pix_array, 2); // obtain the image width, height = svsize (pix_array, 1 ); // obtain the Image Height ADDR = (uint8_t *) svgetarrayptr (pix_array); // open the file fp = Fopen (pic_p, "rb"); If (! FP) return 0; // locate the start of a frame. If (fseek (FP, (uint64_t) (I _frame) * width * height * 3/2, seek_set) return 0; // read the Y component to the memory if (fread (ADDR, 1, width * height, FP) <= 0) return 0; fclose (FP); return 1 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.