目录
简单介绍
io.cpp 主要定义了一些读取图像或者文件,以及它们之间的一些转化的函数。
主要函数
1.ReadProtoFromTextFile 函数:
从prototxt文件中读取message参数
<code class="hljs d has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">bool</span> ReadProtoFromTextFile(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">char</span>* filename, Message* proto) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> fd = open(filename, O_RDONLY);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//打开文件</span> CHECK_NE(fd, -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"File not found: "</span> << filename; FileInputStream* input = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> FileInputStream(fd);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//新建一个FileInputStream对象 input</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">bool</span> success = google::protobuf::TextFormat::Parse(input, proto); <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//解析input文件中的Message, 即使文件中参数定义顺序与Message中的参数定义顺序不一致,也可以解析。</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">delete</span> input; close(fd); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> success; }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li></ul>
2.WriteProtoToTextFile 函数:
<code class="hljs d has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> WriteProtoToTextFile(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> Message& proto, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">char</span>* filename) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>644); FileOutputStream* output = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> FileOutputStream(fd); CHECK(google::protobuf::TextFormat::Print(proto, output)); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">delete</span> output; close(fd);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 和ReadProtoFromTextFile功能相反</span> }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>
3.ReadProtoFromBinaryFile 函数:
从二进制文件中读取message 参数
<code class="hljs d has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">bool</span> ReadProtoFromBinaryFile(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">char</span>* filename, Message* proto) {<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//读取二进制文件</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> fd = open(filename, O_RDONLY); CHECK_NE(fd, -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"File not found: "</span> << filename; ZeroCopyInputStream* raw_input = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> FileInputStream(fd); CodedInputStream* coded_input = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> CodedInputStream(raw_input); <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 建立CodedInputStream类的对象coded_input</span> coded_input->SetTotalBytesLimit(kProtoReadBytesLimit, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">536870912</span>); <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//折设置最大字节限制</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">bool</span> success = proto->ParseFromCodedStream(coded_input);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//解析message</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">delete</span> coded_input; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">delete</span> raw_input; close(fd); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> success; }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li></ul>
4.WriteProtoToBinaryFile 函数 :
<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> WriteProtoToBinaryFile(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> Message& proto, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span>* filename) { fstream output(filename, ios::<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">out</span> | ios::trunc | ios::binary); CHECK(proto.SerializeToOstream(&output)); }<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//和ReadProtoFromBinaryFile功能相反</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul>
5.ReadImageToCVMat 函数:
以cvMat格式读入图像
<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">cv::Mat ReadImageToCVMat(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span>& filename,<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//is_color 为1读入彩色图像,0灰度图</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> height, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> width, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> is_color) { <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//height,width都不为0则把图像resize 到height*width</span> cv::Mat cv_img; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR : CV_LOAD_IMAGE_GRAYSCALE); cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//读入图像</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (!cv_img_origin.data) { LOG(ERROR) << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Could not open or find file "</span> << filename; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> cv_img_origin; } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (height > <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> && width > <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>) { cv::resize(cv_img_origin, cv_img, cv::Size(width, height)); } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> { cv_img = cv_img_origin; } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> cv_img; }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li></ul>
重载函数,提供各种不同的功能
<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">cv::Mat ReadImageToCVMat(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span>& filename, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> height, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> width) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> ReadImageToCVMat(filename, height, width, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>); }<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//重载函数,读入彩色图</span> cv::Mat ReadImageToCVMat(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span>& filename, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> is_color) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> ReadImageToCVMat(filename, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, is_color); }<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//重载函数,读入图像但不resize</span> cv::Mat ReadImageToCVMat(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span>& filename) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> ReadImageToCVMat(filename, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>); }<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//重载函数,读入彩色图像且不resize</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li></ul>
6.matchExt 函数:
匹配文件后缀名
<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">static bool matchExt(const <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">std:</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:string</span> & fn, <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">std:</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:string</span> en) { size_t p = fn.rfind(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'.'</span>);<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//p</span> 为文件名中“.”所在位置的索引 <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">std:</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:string</span> ext = p != fn.npos ? fn.substr(p) <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span> fn;<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//ext</span>为文件后缀名<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">".xxx"</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">std:</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:transform</span>(ext.<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">begin</span>(), ext.<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">end</span>(), ext.<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">begin</span>(), <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:tolower</span>); <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>把ext中的大写字母转化小写字母 <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">std:</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:transform</span>(en.<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">begin</span>(), en.<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">end</span>(), en.<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">begin</span>(), <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:tolower</span>); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> ( ext == en ) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> ( en == <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"jpg"</span> && ext == <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"jpeg"</span> ) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">false</span>; }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li></ul>
7.CVMatToDatum 函数:
cvMat 格式数据转化为Datum格式
<code class="hljs cpp has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> CVMatToDatum(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> cv::Mat& cv_img, Datum* datum) { CHECK(cv_img.depth() == CV_8U) << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Image data type must be unsigned byte"</span>; datum->set_channels(cv_img.channels()); datum->set_height(cv_img.rows); datum->set_width(cv_img.cols);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//分别设置channel, height,width</span> datum->clear_data(); datum->clear_float_data(); datum->set_encoded(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">false</span>); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> datum_channels = datum->channels(); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> datum_height = datum->height(); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> datum_width = datum->width(); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> datum_size = datum_channels * datum_height * datum_width; <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">std</span>::<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">string</span> buffer(datum_size, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">' '</span>);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//将buffer初始化为字符''的datum_size个副本 </span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> h = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; h < datum_height; ++h) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> uchar* ptr = cv_img.ptr<uchar>(h);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//指向图像第h行的指针</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> img_index = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> w = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; w < datum_width; ++w) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> c = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; c < datum_channels; ++c) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> datum_index = (c * datum_height + h) * datum_width + w; buffer[datum_index] = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">static_cast</span><<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span>>(ptr[img_index++]); } } } datum->set_data(buffer); }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li></ul>
8.ReadFileToDatum 函数:
<code class="hljs mel has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">bool ReadFileToDatum(const <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span>& filename, const <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> label, Datum* datum) { std::streampos <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">size</span>;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//获取文件指针位置 size</span> fstream <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">file</span>(filename.c_str(), ios::<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span>|ios::binary|ios::ate); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">file</span>.is_open()) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">size</span> = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">file</span>.tellg();<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//代表当前get 流指针的位置</span> std::<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span> buffer(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">size</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">' '</span>); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">file</span>.seekg(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, ios::beg);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//设置0输入文件流的起始位置</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">file</span>.read(&buffer[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>], <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">size</span>); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">file</span>.close(); datum->set_data(buffer);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//data_->assign(buffer)</span> datum->set_label(label);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//label_ = label</span> datum->set_encoded(true); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> true; } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> false; } }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li></ul>
9.ReadImageToDatum 函数:
读入图像到Datum
<code class="hljs cpp has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> ReadImageToDatum(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">string</span>& filename, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> label, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> height, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> width, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> is_color, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">std</span>::<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">string</span> & encoding, Datum* datum) { cv::Mat cv_img = ReadImageToCVMat(filename, height, width, is_color); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (cv_img.data) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (encoding.size()) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> ( (cv_img.channels() == <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>) == is_color && !height && !width && matchExt(filename, encoding) ) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> ReadFileToDatum(filename, label, datum); <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">std</span>::<span class="hljs-stl_container" style="box-sizing: border-box;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">vector</span><uchar></span> buf; cv::imencode(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"."</span>+encoding, cv_img, buf); datum->set_data(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">std</span>::<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">string</span>(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">reinterpret_cast</span><<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span>*>(&buf[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]), buf.size())); datum->set_label(label); datum->set_encoded(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>; } CVMatToDatum(cv_img, datum);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//cvmat转为Datum格式</span> datum->set_label(label); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>; } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">false</span>; } }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li></ul>
10.DecodeDatumToCVMat 函数:
<code class="hljs cpp has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">cv::Mat DecodeDatumToCVMat(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> Datum& datum, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> is_color) { cv::Mat cv_img; CHECK(datum.encoded()) << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Datum not encoded"</span>; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">string</span>& data = datum.data(); <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">std</span>::<span class="hljs-stl_container" style="box-sizing: border-box;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">vector</span><<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span>></span> vec_data(data.c_str(), data.c_str() + data.size()); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR : CV_LOAD_IMAGE_GRAYSCALE); cv_img = cv::imdecode(vec_data, cv_read_flag);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//从内存都入图片</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (!cv_img.data) { LOG(ERROR) << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Could not decode datum "</span>; } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> cv_img;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//将encode 的Datum转化为cvMat</span> }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li></ul>
11.DecodeDatum 函数:
<code class="hljs cs has-numbering" style="color: inherit; display: block; padding: 0px; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background-image: initial; background-attachment: initial; background-color: transparent; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> DecodeDatum(Datum* datum, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> is_color) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (datum->encoded()) { cv::Mat cv_img = DecodeDatumToCVMat((*datum), is_color); CVMatToDatum(cv_img, datum); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>; } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">false</span>; } }<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//将encodedDatum转化为没有encode的Datum</span></code><code class="hljs cs has-numbering" style="color: inherit; display: block; padding: 0px; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background-image: initial; background-attachment: initial; background-color: transparent; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"> </span></code><code class="hljs cs has-numbering" style="display: block; padding: 0px; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background-image: initial; background-attachment: initial; background-color: transparent; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span style="color:#880000;"> 文章摘自http://blog.csdn.net/seven_first/article/details/47838717#5readimagetocvmat-函数</span></code><ul class="pre-numbering" style="color: rgb(51, 51, 51); box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li></ul>