-
Notifications
You must be signed in to change notification settings - Fork 0
/
2019-08-05-opencv-code.html
31 lines (30 loc) · 11.9 KB
/
2019-08-05-opencv-code.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!DOCTYPE html><html lang="zh-Hans"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=1"><meta name="renderer" content="webkit"><title>OpenCV的学习笔记 | BLOG | HDSKY</title><meta name="format-detection" content="telephone=no"><meta name="description" content="最近抽空的时候会做一个图像处理的项目,也算完成以前没有完成的任务,在此记录下一些学习的过程,希望对其他人能够有所帮助。"><meta name="keywords" content="黑&蛋,个人博客,Linux,Ubuntu,Centos,HPC,tag.name,tag.name"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="applicable-device" content="pc,mobile"><link href="/dist/iris-20b518ec25.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/instantpage.min.js" type="module" defer></script><script>var TinyCache=function(){"use strict";var n=window.localStorage,t=document;function e(n){return new Error("Failed to load "+n.name+": "+n.url)}function r(n){return new Error("No such item or item is staled: "+n.name)}function o(n,e){var r=t.createElement("script");r.id=n.name,r.text=e,r.defer=!0,t.getElementsByTagName("head")[0].appendChild(r)}function i(n,r){var o=t.createElement("script");o.id=n.name,o.src=n.url,o.onload=function(){r(null)},o.onerror=function(){r(e(n))},t.getElementsByTagName("body")[0].appendChild(o)}function u(t,e,r){!function(t,e){try{n.setItem(t,JSON.stringify(e))}catch(t){}}(""+t+e.name,{content:r,expire:e.maxAge?(new Date).getTime()+1e3*e.maxAge:null,name:e.name,url:e.url})}return function(){function t(n){this.config={prefix:"TC:",timeout:6e3},function(n,t){for(var e in t)t.hasOwnProperty(e)&&(n[e]=t[e])}(this.config,n)}var a=t.prototype;return a.load=function(n,t){var e,r,o,i,u=this;if(!t)return new Promise((function(t,e){u.load(n,(function(n){n?e(n):t()}))}));e=n.map((function(n){return function(t){u.loadScript(n,t)}})),r=t,o=[],i=e.length,e.forEach((function(n,t){n((function(n,e){o[t]=e,n&&r&&(r(n),r=null),0==--i&&r&&r(null,o)}))}))},a.remove=function(n){!function(n){try{localStorage.removeItem(n)}catch(n){}}(""+this.config.prefix+n.name)},a.loadScript=function(t,a){var c=this;!function(t,e,o){var i=function(t){var e,r=null;try{var o=n.getItem(t);o&&(r=JSON.parse(o))&&("string"!=typeof(e=r).name||"string"!=typeof e.url||"string"!=typeof e.content)&&(r=null)}catch(t){}return r}(""+t+e.name);i?i.url!==e.url||i.expire&&i.expire<(new Date).getTime()?o(r(e)):o(null,i.content):o(r(e))}(this.config.prefix,t,(function(n,r){var l,f,m,s;n?(l=t,f=c.config.timeout,m=function(n,e){e&&!n?(o(t,e),u(c.config.prefix,t,e),a(null)):i(t,a)},(s=new XMLHttpRequest).open("GET",l.url,!0),s.timeout=f,s.onload=function(){200<=s.status&&s.status<300||304===s.status?m(null,s.responseText):m(e(l))},s.ontimeout=s.onerror=function(){m(e(l))},s.send()):r?(o(t,r),a(null)):i(t,a)}))},t}()}()</script><script>(new TinyCache).load([{url:"/dist/iris-dfae13bc3a.js",name:"iris"}])</script><meta http-equiv="x-dns-prefetch-control" content="on"><link rel="dns-prefetch" href="//www.googletagmanager.com"><link rel="dns-prefetch" href="//hdsky-pw.disqus.com"><link rel="shortcut icon" type="image/ico" href="/favicon.ico"><link rel="icon" type="image/png" href="/favicon-192x192.png"><link rel="apple-touch-icon" href="/apple-touch-icon.png"><link rel="alternate" type="application/atom+xml" href="/atom.xml"><meta property="og:title" content="OpenCV的学习笔记 | BLOG | HDSKY"><meta property="og:type" content="blog"><meta property="og:url" content="https://hdsky.pw/2019-08-05-opencv-code.html"><meta property="og:image" content="/favicon-192x192.png"><meta property="og:description" content="最近抽空的时候会做一个图像处理的项目,也算完成以前没有完成的任务,在此记录下一些学习的过程,希望对其他人能够有所帮助。"><meta property="og:article:tag" content="黑&蛋,个人博客,Linux,Ubuntu,Centos,HPC,tag.name,tag.name"><meta property="og:locale" content="zh-Hans"><meta property="article:published_time" content="Mon Aug 05 2019 00:10:03 GMT+0800"><meta property="article:modified_time" content="Tue Jun 28 2022 00:08:48 GMT+0800"><meta name="twitter:card" content="summary"><script async src="https://www.googletagmanager.com/gtag/js?id=G-BNEM1LH28R"></script><script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","G-BNEM1LH28R")</script><script type="application/ld+json">{
"@context": "http://schema.org",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://hdsky.pw"
},
"headline": "OpenCV的学习笔记",
"datePublished": "2019-08-04T16:10:03.000Z",
"dateModified": "2022-06-27T16:08:48.270Z",
"author": {
"@type": "Person",
"name": "黑&蛋",
"image": {
"@type": "ImageObject",
"url": "avatar.png"
},
"description": "黑&蛋的个人博客"
},
"publisher": {
"@type": "Organization",
"name": "BLOG | HDSKY",
"logo": {
"@type": "ImageObject",
"url": "/favicon-192x192.png"
}
},
"keywords": "黑&蛋,个人博客,Linux,Ubuntu,Centos,HPC,tag.name,tag.name",
"description": "最近抽空的时候会做一个图像处理的项目,也算完成以前没有完成的任务,在此记录下一些学习的过程,希望对其他人能够有所帮助。"
}</script><script>"serviceWorker"in navigator&&navigator.serviceWorker.getRegistrations().then((function(e){e.map((function(e){e.unregister()}))}))</script><meta name="generator" content="Hexo 7.1.1"></head><body data-instant-intensity="viewport"><header class="header header__no-hero"><div class="header-wrapper"><div class="header__left"><div class="header-logo"><a href="/">BLOG | HDSKY</a></div></div><div class="header__right"><nav class="nav"><a id="nav-toggle" class="nav-toggle"><div></div></a><div class="nav-wrapper"><ul><li><a class="nav-link" href="/links">Link</a></li><li><a class="nav-link" href="/archives">Archive</a></li><li><a class="nav-link" href="/about">About</a></li></ul></div></nav></div></div></header><main class="main"><article class="post"><header class="post-header"><h1 class="post-title">OpenCV的学习笔记</h1><section class="post-meta"><time datetime="2019-08-04T16:10:03.000Z"><i class="far fa-calendar" aria-hidden></i> 2019-08-05</time></section></header><aside class="post-aside"><section class="post-toc"><header class="post-toc-title">Contents</header><ol class="post-toc-inst"><li class="post-toc-inst-item post-toc-inst-level-2"><a class="post-toc-inst-link" href="#%E5%86%99%E5%9C%A8%E5%89%8D%E9%9D%A2"><span class="post-toc-inst-number">1.</span> <span class="post-toc-inst-text">写在前面</span></a></li><li class="post-toc-inst-item post-toc-inst-level-2"><a class="post-toc-inst-link" href="#%E6%A3%80%E6%9F%A5OpenCV%E7%89%88%E6%9C%AC"><span class="post-toc-inst-number">2.</span> <span class="post-toc-inst-text">检查OpenCV版本</span></a></li><li class="post-toc-inst-item post-toc-inst-level-2"><a class="post-toc-inst-link" href="#%E6%89%93%E5%BC%80%E5%9B%BE%E7%89%87"><span class="post-toc-inst-number">3.</span> <span class="post-toc-inst-text">打开图片</span></a></li></ol></section></aside><section class="post-content"><p>最近抽空的时候会做一个图像处理的项目,也算完成以前没有完成的任务,在此记录下一些学习的过程,希望对其他人能够有所帮助。<span id="more"></span></p><p>有关于OpenCV的安装以及其他介绍请参考我以前写的一篇<a href="https://hdsky.pw/2016/12/24/opencv-setup/">《OpenCV的学习之路(一)环境的搭建以及和小伙伴Visual Studio的搞基之旅》</a> 当然那篇文章已经是很久以前写的了,有些地方已经不符合现在的情况,还请谅解。</p><h2 id="写在前面"><a href="#写在前面" class="headerlink" title="写在前面"></a>写在前面</h2><p>这几年伴随着各界对于计算机视觉领域关注,计算机视觉领域已经得到很大的发展,除了OpenCV外,在传统计算机视觉领域还有MATLAB也可以作为开发工具。同时,在深度学习引入到机器视觉后很多人也都转向了使用机器学习。</p><p>OpenCV的很多资料在官方的文档中已经写的很详细了,和很多网上的教程也都基于官方的文档进行拓展,在参考网上教程的时候需要多留意一下OpenCV的版本,OpenCV从我关注开始的2版本到我当时使用的3版本,以及现在的最新版本是4,已近进行了多次迭代,不同版本之间的区别应该不小。</p><p>我目前的开发平台是Ubuntu18.04LTS + Python3.7 + OpenCV4.1.0</p><h2 id="检查OpenCV版本"><a href="#检查OpenCV版本" class="headerlink" title="检查OpenCV版本"></a>检查OpenCV版本</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/env python</span></span><br><span class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</span><br><span class="line"><span class="built_in">print</span>(cv.__version__)</span><br></pre></td></tr></table></figure><h2 id="打开图片"><a href="#打开图片" class="headerlink" title="打开图片"></a>打开图片</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/env python</span></span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</span><br><span class="line"></span><br><span class="line"><span class="comment"># Load an color image in grayscale</span></span><br><span class="line">img = cv.imread(<span class="string">'image/j2.jpg'</span>,<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line">cv.imshow(<span class="string">'image'</span>,img)</span><br><span class="line">cv.waitKey(<span class="number">0</span>)</span><br><span class="line">cv.destroyAllWindows()</span><br></pre></td></tr></table></figure></section><footer class="post-meta"><section class="tags"><a href="/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"><i class="fas fa-tag" aria-hidden></i> 学习笔记 </a><a href="/tags/OpenCV/"><i class="fas fa-tag" aria-hidden></i> OpenCV</a></section></footer><div class="post-end" data-text="End"></div></article><section><div id="disqus_thread"></div><script>!function(e){window.DISQUS=null;var s=e.createElement("link");s.rel="stylesheet",s.href="https://cdn.jsdelivr.net/npm/[email protected]/dist/disqusjs.css",e.head.appendChild(s);var n=e.createElement("script");n.async=!0,n.src="https://cdn.jsdelivr.net/npm/[email protected]/dist/disqus.js",n.onload=function(){new DisqusJS({shortname:"hdsky-pw",siteName:"BLOG | HDSKY",identifier:"2019-08-05-opencv-code",url:"https://hdsky.pw/2019-08-05-opencv-code.html",title:"OpenCV的学习笔记",api:"",apikey:"nvPDNH7YoE53bGKClf2CTyHqz9pYcnEsDoMFdpBEdarIrYJNfsdSDrAioHU5292n",admin:"disqus_trck5pCCAM",adminLabel:""})},e.head.appendChild(n)}(document)</script></section></main><footer class="footer"><div class="footer-wrapper"><p class="copyright">© 2016 - 2024 黑&蛋</p><p class="theme">Hexo Theme <a href="https://github.com/giuem/hexo-theme-iris" target="_blank" rel="noopener noreferrer">Iris</a> with <i class="fas fa-heart"></i></p></div></footer></body></html>