CN105262970B - A kind of packaging method based on view data and system - Google Patents
A kind of packaging method based on view data and system Download PDFInfo
- Publication number
- CN105262970B CN105262970B CN201510662625.9A CN201510662625A CN105262970B CN 105262970 B CN105262970 B CN 105262970B CN 201510662625 A CN201510662625 A CN 201510662625A CN 105262970 B CN105262970 B CN 105262970B
- Authority
- CN
- China
- Prior art keywords
- image data
- length
- encapsulated
- data
- packet
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Expired - Fee Related
Links
- 238000000034 method Methods 0.000 title claims abstract description 30
- 238000004806 packaging method and process Methods 0.000 title claims description 20
- 238000005538 encapsulation Methods 0.000 claims abstract description 45
- 238000012856 packing Methods 0.000 claims description 6
- 230000003139 buffering effect Effects 0.000 claims 2
- 238000012795 verification Methods 0.000 claims 1
- 238000004364 calculation method Methods 0.000 abstract description 15
- 238000011161 development Methods 0.000 abstract description 5
- 238000012545 processing Methods 0.000 abstract description 5
- 238000010586 diagram Methods 0.000 description 8
- 230000006872 improvement Effects 0.000 description 8
- 230000005540 biological transmission Effects 0.000 description 5
- 230000018109 developmental process Effects 0.000 description 4
- 230000008569 process Effects 0.000 description 4
- 238000007906 compression Methods 0.000 description 3
- 239000012634 fragment Substances 0.000 description 3
- 238000004458 analytical method Methods 0.000 description 2
- 230000006835 compression Effects 0.000 description 2
- 238000013467 fragmentation Methods 0.000 description 2
- 238000006062 fragmentation reaction Methods 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 230000009977 dual effect Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 239000000284 extract Substances 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000008520 organization Effects 0.000 description 1
- 238000003672 processing method Methods 0.000 description 1
- 230000011218 segmentation Effects 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
Landscapes
- Compression Or Coding Systems Of Tv Signals (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
本发明公开了本发明一种基于图像数据的封装方法及系统,方法包括:将需要封装的图像数据存储于缓存中;根据缓存中的当前帧图像数据总量,计算得出所需封装的图像数据长度;根据计算得到的所需封装的图像数据长度,对图像数据进行打包并封装。系统包括存储单元、长度计算单元和封装单元。本发明在封装时考虑到以太网帧格式和JPEG图像帧数据总量不确定的特点,通过动态计算需打包的图像数据的长度,从而能有效避免需填充无效数据的情况,大大减少数据处理的时间,减少网络带宽的占用,而且本发明实现简单,需求设备较少,能有效缩小开发周期,节约成本。本发明可广泛应用于数据封装领域中。
The invention discloses an image data-based encapsulation method and system of the present invention. The method includes: storing image data to be encapsulated in a cache; calculating the image to be encapsulated according to the total amount of current frame image data in the cache Data length: according to the calculated length of the image data to be packaged, the image data is packaged and packaged. The system includes storage unit, length calculation unit and encapsulation unit. The present invention takes into account the uncertain characteristics of the Ethernet frame format and the total amount of JPEG image frame data when encapsulating, and dynamically calculates the length of the image data to be packaged, thereby effectively avoiding the need to fill invalid data and greatly reducing data processing costs. time, reduce the occupation of network bandwidth, and the invention is simple to implement, requires less equipment, can effectively shorten the development cycle, and save costs. The invention can be widely used in the field of data encapsulation.
Description
技术领域technical field
本发明涉及数据封装技术领域,尤其涉及一种基于图像数据的封装方法及系统。The invention relates to the technical field of data encapsulation, in particular to an encapsulation method and system based on image data.
背景技术Background technique
JPEG是国际标准化组织(ISO)领导下制定的静态图像的压缩编码标准,在图像数据量大、人们对图像质量要求越来越高的背景下,JPEG作为一种低复杂度、高压缩比的图像压缩标准在数据量极大的多媒体以及带宽宝贵的网络传输等领域得到了广泛的应用。而以太网作为一种数据传输标准,其实现简单、价格低廉,且能实现图像数据的高速、稳定、实时的传输,是目前应用最广泛的网络技术。JPEG is a static image compression coding standard formulated under the leadership of the International Organization for Standardization (ISO). Under the background of large amount of image data and people's higher and higher requirements for image quality, JPEG is a low-complexity, high-compression ratio Image compression standards have been widely used in the fields of multimedia with a huge amount of data and network transmission with precious bandwidth. As a data transmission standard, Ethernet is the most widely used network technology at present because it is simple to implement, low in price, and can realize high-speed, stable, and real-time transmission of image data.
在工业现场,由于各种极端的环境和具体应用需求,通常需要对工业设备或现场进行实时的图像采集。目前,国内应用于视频监控领域的图像采集方案多采用CCD图像传感器+视频解码器(如SAA7113H)+FPGA/CPLD+DSP实现。但是这种的现有方案一般开发周期较长,并且在现有的通用图像采集处理系统中,需要用帧缓存模块对图像数据整帧或多帧进行存储,存储设备一般采用SDRAM、SRAM等,这种大容量的高速存储器件成本较高。In industrial sites, due to various extreme environments and specific application requirements, real-time image acquisition of industrial equipment or sites is usually required. At present, most domestic image acquisition solutions used in the field of video surveillance are realized by CCD image sensor + video decoder (such as SAA7113H) + FPGA/CPLD + DSP. However, this kind of existing scheme generally has a long development cycle, and in the existing general-purpose image acquisition and processing system, it is necessary to use a frame buffer module to store the entire frame or multiple frames of image data, and the storage device generally adopts SDRAM, SRAM, etc. Such a high-capacity high-speed memory device has a relatively high cost.
发明内容Contents of the invention
为了解决上述技术问题,本发明的目的是提供一种能缩小开发周期,且节约成本的一种基于图像数据的封装方法及系统。In order to solve the above technical problems, the object of the present invention is to provide a packaging method and system based on image data that can shorten the development cycle and save costs.
本发明所采用的技术方案是:The technical scheme adopted in the present invention is:
一种基于图像数据的封装方法,包括以下步骤:A packaging method based on image data, comprising the following steps:
A、将需要封装的图像数据存储于缓存中;A. Store the image data to be encapsulated in the cache;
B、根据缓存中的当前帧图像数据总量,计算得出所需封装的图像数据长度;B. According to the total amount of the current frame image data in the cache, calculate the length of the image data to be encapsulated;
C、根据计算得到的所需封装的图像数据长度,对图像数据进行打包并封装。C. Packing and packing the image data according to the calculated length of the image data to be packed.
作为所述的一种基于图像数据的封装方法的进一步改进,设K表示允许的最小包文长度,并取允许的最大包文长度为2K,C表示包文中添加的包头与包尾字节数之和,M表示缓存中当前帧图像数据总量,N表示所需封装的图像数据长度;As a further improvement of the encapsulation method based on image data, K represents the minimum allowed packet length, and the maximum allowed packet length is 2K, and C represents the number of header and tail bytes added in the packet The sum, M represents the total amount of image data in the current frame in the cache, and N represents the length of the image data to be encapsulated;
则所述步骤B包括:Then said step B comprises:
B1、若M≥3K-2C,则计算对应的所需封装的图像数据长度N=2K-C;B1. If M≥3K-2C, calculate the corresponding length of image data to be packaged N=2K-C;
B2、若2K-C<M≤3K-2C且M为奇数,则计算对应的所需封装的图像数据长度N=(M+1)/2;B2. If 2K-C<M≤3K-2C and M is an odd number, calculate the corresponding image data length N=(M+1)/2 to be packaged;
B3、若2K-C<M≤3K-2C且M为偶数,则计算对应的所需封装的图像数据长度N=M/2;B3. If 2K-C<M≤3K-2C and M is an even number, calculate the corresponding length of image data to be packaged N=M/2;
B4、若K-C<M≤2K-C,则计算对应的所需封装的图像数据长度N=M;B4. If K-C<M≤2K-C, then calculate the corresponding length of image data to be packaged N=M;
B5、若M<K-C,则计算对应的所需封装的图像数据长度N=0。B5. If M<K-C, calculate the corresponding length of image data to be packaged N=0.
作为所述的一种基于图像数据的封装方法的进一步改进,所述步骤C包括:As a further improvement of the encapsulation method based on image data, the step C includes:
C1、根据计算得到的所需封装的图像数据长度,从缓冲中取出对应长度的图像数据进行打包;C1. According to the calculated length of the image data to be packaged, take out the image data of the corresponding length from the buffer and pack it;
C2、根据取出的图像数据,对其配置对应的包头和包尾;C2. According to the image data taken out, configure the corresponding packet header and packet tail;
C3、根据包头-图像数据-包尾的格式,对打包后的图像数据进行封装。C3. Encapsulate the packaged image data according to the format of packet header-image data-packet trailer.
作为所述的一种基于图像数据的封装方法的进一步改进,所述包头包括有效长度和包文类型。As a further improvement of the encapsulation method based on image data, the packet header includes effective length and packet type.
作为所述的一种基于图像数据的封装方法的进一步改进,所述包尾为校验码。As a further improvement of the encapsulation method based on image data, the packet tail is a check code.
本发明所采用的另一技术方案是:Another technical scheme adopted in the present invention is:
一种基于图像数据的封装系统,包括:A packaging system based on image data, including:
存储单元,用于将需要封装的图像数据存储于缓存中;The storage unit is used to store the image data to be encapsulated in the cache;
长度计算单元,用于根据缓存中的当前帧图像数据总量,计算得出所需封装的图像数据长度;The length calculation unit is used to calculate the length of the image data to be encapsulated according to the total amount of the current frame image data in the cache;
封装单元,用于根据计算得到的所需封装的图像数据长度,对图像数据进行打包并封装。The packaging unit is configured to package and package the image data according to the calculated length of the image data to be packaged.
作为所述的一种基于图像数据的封装系统的进一步改进,设K表示允许的最小包文长度,并取允许的最大包文长度为2K,C表示包文中添加的包头与包尾字节数之和,M表示缓存中当前帧图像数据总量,N表示所需封装的图像数据长度;As a further improvement of the encapsulation system based on image data, let K represent the minimum allowed packet length, and take the allowed maximum packet length as 2K, and C represent the number of header and tail bytes added in the packet The sum, M represents the total amount of image data in the current frame in the cache, and N represents the length of the image data to be encapsulated;
则所述长度计算单元包括:Then the length calculation unit includes:
第一判断计算单元,用于若M≥3K-2C,则计算对应的所需封装的图像数据长度N=2K-C;The first judging calculation unit is used to calculate the corresponding required packaged image data length N=2K-C if M≥3K-2C;
第二判断计算单元,用于若2K-C<M≤3K-2C且M为奇数,则计算对应的所需封装的图像数据长度N=(M+1)/2;The second judging calculation unit is used to calculate the corresponding required packaged image data length N=(M+1)/2 if 2K-C<M≤3K-2C and M is an odd number;
第三判断计算单元,用于若2K-C<M≤3K-2C且M为偶数,则计算对应的所需封装的图像数据长度N=M/2;The third judging calculation unit is used to calculate the corresponding required packaged image data length N=M/2 if 2K-C<M≤3K-2C and M is an even number;
第四判断计算单元,用于若K-C<M≤2K-C,则计算对应的所需封装的图像数据长度N=M;The fourth judging calculation unit is used to calculate the corresponding required packaged image data length N=M if K-C<M≤2K-C;
第五判断计算单元,用于若M<K-C,则计算对应的所需封装的图像数据长度N=0。The fifth judging calculation unit is configured to calculate the corresponding length N=0 of the image data to be packaged if M<K-C.
作为所述的一种基于图像数据的封装系统的进一步改进,所述封装单元包括:As a further improvement of the encapsulation system based on image data, the encapsulation unit includes:
打包单元,用于根据计算得到的所需封装的图像数据长度,从缓冲中取出对应长度的图像数据进行打包;The packaging unit is used to take out the image data of the corresponding length from the buffer for packaging according to the calculated length of the image data to be packaged;
配置单元,用于根据取出的图像数据,对其配置对应的包头和包尾;The configuration unit is used to configure the corresponding packet header and packet tail according to the image data taken out;
封装执行单元,用于根据包头-图像数据-包尾的格式,对打包后的图像数据进行封装。The encapsulation execution unit is used for encapsulating the packaged image data according to the format of packet header-image data-packet trailer.
本发明的有益效果是:The beneficial effects of the present invention are:
本发明一种基于图像数据的封装方法及系统在封装时考虑到以太网帧格式和JPEG图像帧数据总量不确定的特点,通过动态计算需打包的图像数据的长度,从而能有效避免需填充无效数据的情况,大大减少数据处理的时间,减少网络带宽的占用,而且本发明实现简单,需求设备较少,能有效缩小开发周期,节约成本。An image data-based encapsulation method and system of the present invention take into account the uncertain characteristics of the Ethernet frame format and the total amount of JPEG image frame data during encapsulation, and dynamically calculate the length of the image data to be packaged, thereby effectively avoiding the need for filling In the case of invalid data, the time for data processing is greatly reduced, the occupation of network bandwidth is reduced, and the present invention is simple to implement, requires less equipment, can effectively shorten the development cycle, and save costs.
附图说明Description of drawings
下面结合附图对本发明的具体实施方式作进一步说明:The specific embodiment of the present invention will be further described below in conjunction with accompanying drawing:
图1是本发明一种基于图像数据的封装方法的步骤流程图;Fig. 1 is a flow chart of steps of a packaging method based on image data in the present invention;
图2是本发明一种基于图像数据的封装方法步骤C的步骤流程图;Fig. 2 is a step flow chart of step C of a packaging method based on image data in the present invention;
图3是本发明一种基于图像数据的封装系统的模块方框图;Fig. 3 is a block diagram of modules of a packaging system based on image data in the present invention;
图4是本发明数据封装包的包文格式示意图;Fig. 4 is a schematic diagram of the packet text format of the data encapsulation packet of the present invention;
图5是本发明实现过程的系统功能框图;Fig. 5 is the system functional block diagram of the realization process of the present invention;
图6是本发明实现过程的FPGA功能模块实现框图;Fig. 6 is the FPGA functional module realization block diagram of the present invention's realization process;
图7是本发明实现过程中封装方法的FPGA实现框图。Fig. 7 is a FPGA implementation block diagram of the encapsulation method in the implementation process of the present invention.
具体实施方式Detailed ways
参考图1,本发明一种基于图像数据的封装方法,包括以下步骤:With reference to Fig. 1, a kind of packaging method based on image data of the present invention comprises the following steps:
A、将需要封装的图像数据存储于缓存中;A. Store the image data to be encapsulated in the cache;
B、根据缓存中的当前帧图像数据总量,计算得出所需封装的图像数据长度;B. According to the total amount of the current frame image data in the cache, calculate the length of the image data to be encapsulated;
C、根据计算得到的所需封装的图像数据长度,对图像数据进行打包并封装。C. Packing and packing the image data according to the calculated length of the image data to be packed.
进一步作为优选的实施方式,设K表示允许的最小包文长度,并取允许的最大包文长度为2K,C表示包文中添加的包头与包尾字节数之和,M表示缓存中当前帧图像数据总量,N表示所需封装的图像数据长度;Further as a preferred embodiment, let K represent the minimum packet length allowed, and get the maximum packet length allowed to be 2K, C represents the sum of the header and tail bytes added in the packet, and M represents the current frame in the cache The total amount of image data, N represents the length of image data to be packaged;
则所述步骤B包括:Then said step B comprises:
B1、若M≥3K-2C,则计算对应的所需封装的图像数据长度N=2K-C;B1. If M≥3K-2C, calculate the corresponding length of image data to be packaged N=2K-C;
B2、若2K-C<M≤3K-2C且M为奇数,则计算对应的所需封装的图像数据长度N=(M+1)/2;B2. If 2K-C<M≤3K-2C and M is an odd number, calculate the corresponding image data length N=(M+1)/2 to be packaged;
B3、若2K-C<M≤3K-2C且M为偶数,则计算对应的所需封装的图像数据长度N=M/2;B3. If 2K-C<M≤3K-2C and M is an even number, calculate the corresponding length of image data to be packaged N=M/2;
B4、若K-C<M≤2K-C,则计算对应的所需封装的图像数据长度N=M;B4. If K-C<M≤2K-C, then calculate the corresponding length of image data to be packaged N=M;
B5、若M<K-C,则计算对应的所需封装的图像数据长度N=0。B5. If M<K-C, calculate the corresponding length of image data to be packaged N=0.
参考图2,进一步作为优选的实施方式,所述步骤C包括:Referring to Fig. 2, further as a preferred embodiment, the step C includes:
C1、根据计算得到的所需封装的图像数据长度,从缓冲中取出对应长度的图像数据进行打包;C1. According to the calculated length of the image data to be packaged, take out the image data of the corresponding length from the buffer and pack it;
C2、根据取出的图像数据,对其配置对应的包头和包尾;C2. According to the image data taken out, configure the corresponding packet header and packet tail;
C3、根据包头-图像数据-包尾的格式,对打包后的图像数据进行封装。C3. Encapsulate the packaged image data according to the format of packet header-image data-packet trailer.
参考图4,进一步作为优选的实施方式,所述包头包括有效长度和包文类型。所述包尾为校验码。Referring to FIG. 4 , as a further preferred implementation manner, the packet header includes an effective length and a packet type. The tail of the packet is a check code.
其中,所述有效长度指示数据封装包的有效数据字节数,即为包文类型、图像数据和校验码的字节数总和,在数据接收端,先接收此字节,然后根据此字节的指示确定接收数据的长度;所述包文类型,主要用于标示数据源或目的,如0x01标示摄像头1的数据,0x02标示摄像头2的数据;图像数据,表示实际需要传输的JPEG数据;校验码,根据图像数据生成的16bit的CRC校验码,用于接收端对接收的包文数据进行校验,当校验不通过时,进行错误包文统计并对当前图像帧作出相应处理。Wherein, the effective length indicates the number of effective data bytes of the data encapsulation package, which is the sum of the number of bytes of the packet type, image data and check code. At the data receiving end, first receive this byte, and then according to this word The instructions in the section determine the length of the received data; the packet type is mainly used to indicate the data source or purpose, such as 0x01 indicates the data of the camera 1, and 0x02 indicates the data of the camera 2; the image data indicates the JPEG data that actually needs to be transmitted; Check code, a 16-bit CRC check code generated according to the image data, used by the receiving end to check the received packet data, when the check fails, the error packet statistics are performed and the current image frame is processed accordingly .
参考图3,本发明一种基于图像数据的封装系统,包括:With reference to Fig. 3, a kind of encapsulation system based on image data of the present invention comprises:
存储单元,用于将需要封装的图像数据存储于缓存中;The storage unit is used to store the image data to be encapsulated in the cache;
长度计算单元,用于根据缓存中的当前帧图像数据总量,计算得出所需封装的图像数据长度;The length calculation unit is used to calculate the length of the image data to be encapsulated according to the total amount of the current frame image data in the cache;
封装单元,用于根据计算得到的所需封装的图像数据长度,对图像数据进行打包并封装。The packaging unit is configured to package and package the image data according to the calculated length of the image data to be packaged.
作为所述的一种基于图像数据的封装系统的进一步改进,设K表示允许的最小包文长度,并取允许的最大包文长度为2K,C表示包文中添加的包头与包尾字节数之和,M表示缓存中当前帧图像数据总量,N表示所需封装的图像数据长度;As a further improvement of the encapsulation system based on image data, let K represent the minimum allowed packet length, and take the allowed maximum packet length as 2K, and C represent the number of header and tail bytes added in the packet The sum, M represents the total amount of image data in the current frame in the cache, and N represents the length of the image data to be encapsulated;
则所述长度计算单元包括:Then the length calculation unit includes:
第一判断计算单元,用于若M≥3K-2C,则计算对应的所需封装的图像数据长度N=2K-C;The first judging calculation unit is used to calculate the corresponding required packaged image data length N=2K-C if M≥3K-2C;
第二判断计算单元,用于若2K-C<M≤3K-2C且M为奇数,则计算对应的所需封装的图像数据长度N=(M+1)/2;The second judging calculation unit is used to calculate the corresponding required packaged image data length N=(M+1)/2 if 2K-C<M≤3K-2C and M is an odd number;
第三判断计算单元,用于若2K-C<M≤3K-2C且M为偶数,则计算对应的所需封装的图像数据长度N=M/2;The third judging calculation unit is used to calculate the corresponding required packaged image data length N=M/2 if 2K-C<M≤3K-2C and M is an even number;
第四判断计算单元,用于若K-C<M≤2K-C,则计算对应的所需封装的图像数据长度N=M;The fourth judging calculation unit is used to calculate the corresponding required packaged image data length N=M if K-C<M≤2K-C;
第五判断计算单元,用于若M<K-C,则计算对应的所需封装的图像数据长度N=0。The fifth judging calculation unit is configured to calculate the corresponding length N=0 of the image data to be packaged if M<K-C.
作为所述的一种基于图像数据的封装系统的进一步改进,所述封装单元包括:As a further improvement of the encapsulation system based on image data, the encapsulation unit includes:
打包单元,用于根据计算得到的所需封装的图像数据长度,从缓冲中取出对应长度的图像数据进行打包;The packaging unit is used to take out the image data of the corresponding length from the buffer for packaging according to the calculated length of the image data to be packaged;
配置单元,用于根据取出的图像数据,对其配置对应的包头和包尾;The configuration unit is used to configure the corresponding packet header and packet tail according to the image data taken out;
封装执行单元,用于根据包头-图像数据-包尾的格式,对打包后的图像数据进行封装。The encapsulation execution unit is used for encapsulating the packaged image data according to the format of packet header-image data-packet trailer.
在对数据进行封装时,封装包文长度的确定,要综合考虑以太网帧格式和JPEG图像帧数据总量不确定的特点。在对JPEG图像帧取某定长分片时(如256Byte),因其帧数据总量不确定,那么最后一个分片的长度也不确定,这样就会出现低于46Byte的图像包文,此时常见的有两种处理方式:一是在对数据分片进行封装时,封装包的长度恒定不变,出现不满足长度的分片,在封装数据包时通过填充无效数据使其满足规定长度;还有一种方法是直接发送,由以太网端自动填充的无效数据。以上两种方法均存在无效数据填充,增加了数据处理时间,浪费了以太网带宽。为了避免小于46Byte的包文出现,本系统提出了不定长的数据封装方法,实现更高效的数据传输。When encapsulating the data, the determination of the length of the encapsulation package should take into account the uncertain characteristics of the Ethernet frame format and the total amount of JPEG image frame data. When taking a fixed-length slice (such as 256Byte) for a JPEG image frame, because the total amount of frame data is uncertain, the length of the last slice is also uncertain, so that there will be an image packet lower than 46Byte. There are two common processing methods: one is when encapsulating data fragments, the length of the encapsulation packet is constant, and there are fragments that do not meet the length. When encapsulating the data packet, invalid data is filled to make it meet the specified length ; Another method is to send directly, invalid data automatically filled by the Ethernet side. Both of the above two methods have invalid data filling, which increases the data processing time and wastes the Ethernet bandwidth. In order to avoid the occurrence of packets smaller than 46Byte, this system proposes a data encapsulation method with variable length to achieve more efficient data transmission.
本发明的具体实施例如下:Specific embodiments of the present invention are as follows:
本发明实施例中,设允许的最小包文长度K为128 Byte,则允许的最大包文长度2K为256 Byte,包文中添加的包头与包尾字节数之和C为4 Byte,M表示缓存中当前帧图像数据总量,N表示所需封装的图像数据长度。In the embodiment of the present invention, if the allowed minimum packet length K is 128 Byte, then the allowed maximum packet length 2K is 256 Byte, and the sum C of the header and tail bytes added in the packet is 4 Byte, and M represents The total amount of image data in the current frame in the cache, and N represents the length of the image data to be encapsulated.
S1、将需要封装的图像数据存储于缓存中;S1. Store the image data to be encapsulated in the cache;
S2、根据缓存中的当前帧图像数据总量,计算得出所需封装的图像数据长度,具体如下:S2. According to the total amount of the current frame image data in the buffer, calculate the length of the image data to be encapsulated, specifically as follows:
若M≥376 Byte,则计算对应的所需封装的图像数据长度N=252 Byte;If M≥376 Byte, calculate the corresponding required packaged image data length N=252 Byte;
若252 Byte<M≤376 Byte且M为奇数,则计算对应的所需封装的图像数据长度N=(M+1)/2;If 252 Byte<M≤376 Byte and M is an odd number, calculate the corresponding length of image data to be packaged N=(M+1)/2;
若252 Byte<M≤376 Byte且M为偶数,则计算对应的所需封装的图像数据长度N=M/2;If 252 Byte<M≤376 Byte and M is an even number, then calculate the corresponding required packaged image data length N=M/2;
若124 Byte<M≤252 Byte,则计算对应的所需封装的图像数据长度N=M;If 124 Byte<M≤252 Byte, then calculate the corresponding length of the image data to be packaged N=M;
若M<124 Byte,则计算对应的所需封装的图像数据长度N=0,此时表示不进行数据封装操作;If M<124 Byte, then calculate the corresponding image data length N=0 that needs to be encapsulated, which means that no data encapsulation operation is performed at this time;
S3、根据计算得到的所需封装的图像数据长度,从缓冲中取出对应长度的图像数据进行打包;S3. According to the calculated length of the image data to be packaged, the image data of the corresponding length is taken out from the buffer and packed;
S4、根据取出的图像数据,对其配置对应的包头和包尾;S4. According to the image data taken out, configure the corresponding packet header and packet tail;
S5、根据包头-图像数据-包尾的格式,对打包后的图像数据进行封装。S5. Encapsulate the packaged image data according to the packet header-image data-packet trailer format.
本发明在FPGA环境下的实现过程如下:The realization process of the present invention under FPGA environment is as follows:
系统实现双摄像头的图像采集功能。摄像头图像数据经FPGA采集处理后,经以太网传输给上位机,上位机端对接收的JPEG数据进行解码并实时显示,同时上位机也具有对下位机的配置或控制功能,系统功能框图如图5所示。The system realizes the image acquisition function of dual cameras. After the camera image data is collected and processed by the FPGA, it is transmitted to the host computer via Ethernet. The host computer decodes the received JPEG data and displays it in real time. At the same time, the host computer also has the configuration or control function for the lower computer. The system function block diagram is shown in the figure 5.
FPGA功能模块的实现框图如图6所示,系统工作时,由W5300配置模块完成对W5300的配置,实现TCP协议的以太网通信,然后PC上位机发送配置命令,经以太网传输给FPGA,FPGA对配置命令进行解析并完成对两路OV2640摄像头的配置,OV2640按照具体配置输出JPEG图像数据,再由FPGA完成对图像数据的分片、封装处理,经过处理的两路图像数据最终经以太网传输给上位机分别显示,上位机端在对图像实时显示的同时可以随时发送控制命令,并经指令解析模块解析,完成暂停某路图像的接收、改变图像输出分辨率、帧率等功能。The realization block diagram of the FPGA function module is shown in Figure 6. When the system is working, the W5300 configuration module completes the configuration of the W5300, realizes the Ethernet communication of the TCP protocol, and then the PC host computer sends configuration commands to the FPGA through the Ethernet, and the FPGA Analyze the configuration command and complete the configuration of the two-way OV2640 camera. OV2640 outputs JPEG image data according to the specific configuration, and then the FPGA completes the segmentation and packaging of the image data. The processed two-way image data is finally transmitted via Ethernet The upper computer can display the image separately, and the upper computer can send control commands at any time while displaying the image in real time, and through the analysis of the instruction analysis module, it can complete functions such as pausing the reception of a certain image, changing the image output resolution, and frame rate.
数据封装模块完成图像帧的分片、封装功能,将采集到的原始图像帧数据转化为若干图像包文,是实现基于图像分片封装包文的核心,下面对该模块的实现进行说明。The data encapsulation module completes the fragmentation and encapsulation of image frames, and converts the collected original image frame data into several image envelopes, which is the core of encapsulating envelopes based on image slices. The implementation of this module will be described below.
在FPGA中,用两个FIFO分别对两路图像数据进行缓存,具体实现时,不定长数据封装方法的K和C的值以及FIFO的宽度、深度均以参数化定义,这样可以很方便的调整数据封装包的格式。本系统实现时,取K值为128Byte,考虑到一定的数据突发因素,取单个FIFO深度为1024、宽度为10(帧开始、结束各1bit,图像数据8bit)。实现框图如图7所示。In the FPGA, two FIFOs are used to cache the two-way image data respectively. In the specific implementation, the values of K and C in the variable-length data encapsulation method and the width and depth of the FIFO are all parameterized, which can be easily adjusted. The format of the data encapsulation packet. When this system is implemented, the value of K is 128Byte. Considering certain data burst factors, the depth of a single FIFO is 1024, and the width is 10 (1 bit for the start and end of the frame, and 8 bits for image data). The realization block diagram is shown in Figure 7.
上述方法中,数据缓存的读写两侧是相互独立的,可以同时进行,这符合图像数据随时到来的特点,因此数据段打包不会影响图像数据的传输速度。但须注意,使用前述不定长数据封装的M是当前帧的数据总量,而非缓存中有数据的总量,因为图像数据是随时到来的,若当前图像帧数据尚未封装完毕,而下一帧图像又到来时,缓存中将同时存在两帧的图像数据。In the above method, the read and write sides of the data cache are independent of each other and can be performed simultaneously, which conforms to the feature that the image data arrives at any time, so the data segment packaging will not affect the transmission speed of the image data. However, it should be noted that M, which is encapsulated with the aforementioned indefinite length data, is the total amount of data in the current frame, not the total amount of data in the cache, because the image data comes at any time, if the current image frame data has not been encapsulated, and the next When a frame image comes again, there will be two frames of image data in the cache.
动态包长模块即是根据前述不定长数据封装算法实现。在FPGA中,它依据数据封装模块是否空闲以及FIFO中当前图像帧的数据量产生读FIFO数据长度值,因为系统有两个FIFO,实现时要根据具体FIFO中的数据量选择所读取的FIFO,若两个FIFO中的数据均满足取数据要求,则对两个FIFO进行轮流选择。所读的FIFO以及读数据量确定后,FIFO根据给定的长度值输出指定长度的图像数据;CRC16码生成模块产生输出图像数据的CRC16校验码;最终,图像数据经数据封装模块添加相应的包头、包尾生成图像包文。这样就完成了对一帧数据的完整分片、封装。The dynamic packet length module is realized according to the aforementioned variable-length data encapsulation algorithm. In the FPGA, it generates the read FIFO data length value based on whether the data encapsulation module is free and the data volume of the current image frame in the FIFO, because the system has two FIFOs, and the read FIFO should be selected according to the data volume in the specific FIFO during implementation. , if the data in the two FIFOs all meet the data fetching requirements, the two FIFOs are selected in turn. After the read FIFO and the amount of read data are determined, the FIFO outputs the image data of the specified length according to the given length value; the CRC16 code generation module generates the CRC16 check code of the output image data; finally, the image data is added to the corresponding image data by the data encapsulation module Packet header and packet tail generate image packet text. In this way, the complete fragmentation and encapsulation of a frame of data is completed.
最后图像帧数据以图像包文为单位传输给W5300接口,经以太网传输给上位机,上位机端根据发送端的数据封装协议提取图像数据,并对数据分片进行重组,最后对重组的JPEG图像帧进行解码并实时显示,完成图像采集任务。Finally, the image frame data is transmitted to the W5300 interface in units of image packets, and transmitted to the host computer via Ethernet. The host computer extracts the image data according to the data encapsulation protocol of the sending end, and reorganizes the data fragments, and finally reorganizes the JPEG image The frame is decoded and displayed in real time to complete the image acquisition task.
从上述内容可知,本发明一种基于图像数据的封装方法及系统在封装时考虑到以太网帧格式和JPEG图像帧数据总量不确定的特点,通过动态计算需打包的图像数据的长度,从而能有效避免需填充无效数据的情况,大大减少数据处理的时间,减少网络带宽的占用,而且本发明实现简单,需求设备较少,能有效缩小开发周期,节约成本。As can be seen from the foregoing, a kind of encapsulation method and system based on image data of the present invention considers the uncertain characteristics of the Ethernet frame format and the total amount of JPEG image frame data during encapsulation, and dynamically calculates the length of the image data to be packaged, thereby It can effectively avoid the situation that invalid data needs to be filled, greatly reduce the time for data processing, and reduce the occupation of network bandwidth, and the invention is simple to implement, requires less equipment, can effectively shorten the development cycle, and save costs.
以上是对本发明的较佳实施进行了具体说明,但本发明创造并不限于所述实施例,熟悉本领域的技术人员在不违背本发明精神的前提下还可做作出种种的等同变形或替换,这些等同的变形或替换均包含在本申请权利要求所限定的范围内。The above is a specific description of the preferred implementation of the present invention, but the invention is not limited to the described embodiments, and those skilled in the art can also make various equivalent deformations or replacements without violating the spirit of the present invention. , these equivalent modifications or replacements are all within the scope defined by the claims of the present application.
Claims (6)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201510662625.9A CN105262970B (en) | 2015-10-14 | 2015-10-14 | A kind of packaging method based on view data and system |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201510662625.9A CN105262970B (en) | 2015-10-14 | 2015-10-14 | A kind of packaging method based on view data and system |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN105262970A CN105262970A (en) | 2016-01-20 |
| CN105262970B true CN105262970B (en) | 2018-12-04 |
Family
ID=55102457
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201510662625.9A Expired - Fee Related CN105262970B (en) | 2015-10-14 | 2015-10-14 | A kind of packaging method based on view data and system |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN105262970B (en) |
Families Citing this family (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109345442A (en) * | 2018-09-17 | 2019-02-15 | 昆明理工大学 | An FPGA lucky imaging system and method based on Ethernet transmission |
| CN110290288B (en) * | 2019-06-03 | 2022-01-04 | Oppo广东移动通信有限公司 | Image processor, image processing method, photographing device, and electronic apparatus |
| CN112100169B (en) * | 2020-08-05 | 2021-09-21 | 中科驭数(北京)科技有限公司 | Database interaction data encoding method and device |
Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1571415A (en) * | 2003-07-17 | 2005-01-26 | 华为技术有限公司 | A method for packaging data stream |
| CN1720705A (en) * | 2002-12-04 | 2006-01-11 | 皇家飞利浦电子股份有限公司 | Packaging of layered media bitstreams |
| CN1972453A (en) * | 2006-11-30 | 2007-05-30 | 中兴通讯股份有限公司 | A data flow packaging method of mobile multimedia broadcasting system |
| CN101674498A (en) * | 2008-09-12 | 2010-03-17 | 华为技术有限公司 | A method, device and system for transmitting constant rate data stream |
| CN101753586A (en) * | 2010-01-20 | 2010-06-23 | 北京数码视讯科技股份有限公司 | Method for transmitting data, process method for receiving data and device |
| CN101860737A (en) * | 2009-04-10 | 2010-10-13 | 杭州海康威视数字技术股份有限公司 | Packaging method and device of MPEG2 system layer for reducing transmission time delay |
| CN103051981A (en) * | 2012-11-16 | 2013-04-17 | 北京邮电大学 | Adaptive frame size calculation method for multiple hop transmission of video |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| KR101670723B1 (en) * | 2011-01-04 | 2016-11-01 | 삼성전자주식회사 | Apparatus and method for supporting variable length of transport packet in video and audio commnication system |
-
2015
- 2015-10-14 CN CN201510662625.9A patent/CN105262970B/en not_active Expired - Fee Related
Patent Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1720705A (en) * | 2002-12-04 | 2006-01-11 | 皇家飞利浦电子股份有限公司 | Packaging of layered media bitstreams |
| CN1571415A (en) * | 2003-07-17 | 2005-01-26 | 华为技术有限公司 | A method for packaging data stream |
| CN1972453A (en) * | 2006-11-30 | 2007-05-30 | 中兴通讯股份有限公司 | A data flow packaging method of mobile multimedia broadcasting system |
| CN101674498A (en) * | 2008-09-12 | 2010-03-17 | 华为技术有限公司 | A method, device and system for transmitting constant rate data stream |
| CN101860737A (en) * | 2009-04-10 | 2010-10-13 | 杭州海康威视数字技术股份有限公司 | Packaging method and device of MPEG2 system layer for reducing transmission time delay |
| CN101753586A (en) * | 2010-01-20 | 2010-06-23 | 北京数码视讯科技股份有限公司 | Method for transmitting data, process method for receiving data and device |
| CN103051981A (en) * | 2012-11-16 | 2013-04-17 | 北京邮电大学 | Adaptive frame size calculation method for multiple hop transmission of video |
Also Published As
| Publication number | Publication date |
|---|---|
| CN105262970A (en) | 2016-01-20 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN109089029B (en) | An FPGA-based Gige Vision interface image transmission system and method | |
| CN103929681B (en) | Method for improving RTP video streaming treatment efficiency in low-speed network | |
| CN105262970B (en) | A kind of packaging method based on view data and system | |
| CN110896431B (en) | Non-compression high-definition video transmission method and system | |
| CN101267293A (en) | Streaming Media Covert Communication Method Based on Hierarchical Model | |
| CN103346949A (en) | Unpacking and packing method and system based on embedded two-channel network data package | |
| CN110620637B (en) | Data decompression device and method based on FPGA | |
| CN103795593A (en) | Testing system and method of uplink of high-speed communication processor of spaceship | |
| CN110971909A (en) | Low-power-consumption low-delay SOC chip | |
| CN110087140A (en) | A kind of method, apparatus, medium and equipment for transmitting stream medium data | |
| CN101656588A (en) | Method and system for transmitting data | |
| CN104168439A (en) | Video coding method and apparatus | |
| CN114531332A (en) | Data transmission method, data processing method, device and storage medium | |
| CN101521813B (en) | Method and device for processing media stream | |
| CN108124157B (en) | Information interaction method, device and system | |
| CN110996120A (en) | Video stream transmitting and receiving method | |
| CN101505420B (en) | Encapsulation method for video compression data | |
| CN114096009B (en) | Flexible and efficient multi-class data dynamic framing method | |
| US20190347238A1 (en) | Systems and methods for data transfer over a shared interface | |
| CN105897929A (en) | Video monitoring data backup method and device | |
| CN103634229B (en) | A kind of Inter-chip communication method and control device | |
| CN104244085B (en) | Multimedia data transmission method and device based on field programmable gate array | |
| CN111711745B (en) | Portable cameralink data acquisition system and acquisition method | |
| CN115942000A (en) | Video stream transcoding method, device, equipment and medium based on H.264 format | |
| CN111181682A (en) | Implementation method for GFP frame fragmentation transmission based on FPGA |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| C06 | Publication | ||
| PB01 | Publication | ||
| C10 | Entry into substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant | ||
| CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20181204 Termination date: 20211014 |
|
| CF01 | Termination of patent right due to non-payment of annual fee |