<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>libgtk2.0-dev &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/tag/libgtk2-0-dev/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Mon, 27 Apr 2020 17:06:49 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>[原创] 解决ELL demo的 OpenCV Error: Unspecified error in cvShowImage 错误</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3ell-demo%e7%9a%84-opencv-error-unspecified-error-in-cvshowimage-%e9%94%99%e8%af%af/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3ell-demo%e7%9a%84-opencv-error-unspecified-error-in-cvshowimage-%e9%94%99%e8%af%af/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Mon, 17 Jul 2017 16:17:36 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[ELL]]></category>
		<category><![CDATA[libgtk2.0-dev]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Unspecified error in cvShowImage]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=9473</guid>

					<description><![CDATA[<p>
OS：Ubuntu 14.04 LTS</p>
<p>在<a href="https://github.com/Microsoft/ELL" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">ELL</span></a>的<a href="https://github.com/Microsoft/ELL/blob/master/tutorials/vision/gettingStarted/cntk.md" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">tutorial</span></a>中，有一个步骤是在PC上测试运行一个demo程序来检查ELL能否正常工作，当你选择CNTK model的时候，运行的就是 <span style="color:#0000ff;">cntkDemo.py</span> 这个demo程序。<br />
<span id="more-9473"></span><br />
这个demo程序调用了OpenCV来在GUI窗口中显示摄像头拍摄的实时视频，可能会跑不起来，并输出下面这样的错误：</p>
<blockquote>
<p>
		OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /feedstock_root/build_artefacts/opencv_1490907195496/work/opencv-3.2.0/modules/highgui/src/window.cpp,</p></blockquote>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3ell-demo%e7%9a%84-opencv-error-unspecified-error-in-cvshowimage-%e9%94%99%e8%af%af/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<p>
OS：Ubuntu 14.04 LTS</p>
<p>在<a href="https://github.com/Microsoft/ELL" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">ELL</span></a>的<a href="https://github.com/Microsoft/ELL/blob/master/tutorials/vision/gettingStarted/cntk.md" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">tutorial</span></a>中，有一个步骤是在PC上测试运行一个demo程序来检查ELL能否正常工作，当你选择CNTK model的时候，运行的就是 <span style="color:#0000ff;">cntkDemo.py</span> 这个demo程序。<br />
<span id="more-9473"></span><br />
这个demo程序调用了OpenCV来在GUI窗口中显示摄像头拍摄的实时视频，可能会跑不起来，并输出下面这样的错误：</p>
<blockquote>
<p>
		OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /feedstock_root/build_artefacts/opencv_1490907195496/work/opencv-3.2.0/modules/highgui/src/window.cpp, ...（后面还有很长的内容）</p>
</blockquote>
<p>如果你的PC和我的一样老旧，那么执行 <span style="color:#0000ff;">python cntkDemo.py</span> 可能耗时非常长（你可以在一台老爷车上试一下），直到N分钟后才打印出上面的错误，然后程序挂掉，这使得我们解决这个问题非常不方便&mdash;&mdash;每次都要等待超级长的时间，才知道自己的修改是否有效。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
因此，为了能便于debug问题，我们先把和上面那个错误相关的关键代码段提取出来，单独放到一个源代码文件 z.py 中：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="python language-python hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;numpy&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">as</span>&nbsp;np
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;cv2
cam&nbsp;=&nbsp;cv2.VideoCapture(<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">0</span>)
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">while</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">True</span>:
&nbsp;&nbsp;&nbsp;&nbsp;ret,&nbsp;frame&nbsp;=&nbsp;cam.read()
&nbsp;&nbsp;&nbsp;&nbsp;cv2.imshow(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;test&#39;</span>,&nbsp;frame)
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">if</span>&nbsp;cv2.waitKey(<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">1</span>)&nbsp;&amp;&nbsp;<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">0xFF</span>&nbsp;==&nbsp;<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">27</span>:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">break</span></code></pre>
</section>
<p>稍后，我们只需要执行 <span style="color:#0000ff;">python z.py</span>，不出错的话，就说明我们搞定了以上问题。<br />
注意：这里的程序假设你的Ubuntu PC上至少连接了一个USB摄像头，cv2.VideoCapture(0)里的0就是指第一个摄像头，千万不要傻傻地在没有摄像头的情况下测试。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<div>
	其实，打印出的错误信息已经告诉我们，如果你使用的是Ubuntu，需要安装&nbsp;<span style="color:#0000ff;">libgtk2.0-dev</span> 和 <span style="color:#0000ff;">pkg-config</span>，然后rebuild软件。这里没有写清楚到底是rebuild OpenCV还是ELL，但我理解应该是指OpenCV。不过根据我的试验，把系统里的OpenCV卸载掉，并且把miniconda环境里的OpenCV也卸载掉，然后安装&nbsp;libgtk2.0-dev 和 pkg-config，再按ELL doc的方法把miniconda环境里的OpenCV装上，并不能fix这个问题。<br />
	经过漫长的Google搜索，我最终找到了问题的原因：ELL文档中提供的安装opencv的方法有问题（至少在我的Ubuntu上如此）：</div>
<blockquote>
<div>
		conda install -c conda-forge opencv</div>
</blockquote>
<div>
	这样安装上的OpenCV，在运行<span style="color:#0000ff;">&nbsp;cntkDemo.py</span> 的时候就会出上面的错。</div>
<div>
	&nbsp;</div>
<div>
	我在Stack Overflow上找到的一个解决方案是，你应该在conda环境下，用下面的方法来安装OpenCV：</div>
<blockquote>
<div>
		conda install --channel loopbio --channel conda-forge --channel pkgw-forge gtk2 ffmpeg ffmpeg-feature gtk2-feature opencv</div>
</blockquote>
<div>
	这样安装好了OpenCV之后，再运行 python z.py，你就会看到它神奇地解决了问题：马上弹出了一个图形窗口，里面显示的就是摄像头拍摄的实时视频。<br />
	当然，在安装之前，如果已经装错了另一个版本的OpenCV，需要先用 <span style="color:#0000ff;">conda remove opencv</span> 卸载掉。关于这个错误的详解可以看<a href="https://stackoverflow.com/questions/40207011/opencv-not-working-properly-with-python-on-linux-with-anaconda-getting-error-th" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">这个</span></a>和<a href="https://github.com/conda-forge/opencv-feedstock/issues/43" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">这个</span></a>链接。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
		<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3ell-demo%e7%9a%84-opencv-error-unspecified-error-in-cvshowimage-%e9%94%99%e8%af%af/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
