python-2.7 - 我的opencv python程序显示看似期望的短语,但既不终止也不允许进度

标签 python-2.7 opencv opengl ubuntu-12.04

我在使用某个程序时遇到麻烦
想要从openCV执行sobel派生以找到图片中的边缘。我发现此代码的python改编:
sobel_derivatives.html#sobel-derivatives
来自opencv教程
在此地址上:
Official_Tutorial_Python_Codes / 3_imgproc / sobel.py
我想复制并适应在网上找到的图片上运行。
经过一些调试,并以“sudo”身份运行程序之后,我仅收到以下消息:

初始化完成

可用的OpenGL支持

prgram永不终止。我无法使用ctrl + c或任何其他此类命令(我正在从PuTTy客户端访问ubuntu OS),我重试的唯一选择是停止并重新启动 session 。

我的问题似乎与此类似:
可以完成init-opengl支持
但我似乎无法完全解决,也无法在该线程上发表进一步的问题。据我所知,我的openCV2似乎有错误。我尝试使用“sudo apt-get install”重新下载它,但没有任何变化。
我的代码如下所示:

"""
Sobel_derivation.py

attempt at finding the derivatives in a picture.
this is extremely beginner-level coding, so please
bear with me. Might also take a look at the supposedly
more accurate 'Scharr' derivatives.

mostly imported and attempted to interpret from
https://github.com/abidrahmank/OpenCV2-Python/blob/master/Official_Tutorial_Python_Codes/3_imgproc/sobel.py
"""

import cv2 # this is the currently installed version of openCV
import numpy as np # useful tool for most array-based computing

scale = 1 # for scaling the derivatives in the x and y direction
delta = 0 # optional value, here apparently set as trivial (also, mostly
#important for the 'Scharr' function from what I can see.
#ddepth = cv2.CV_16u # output image depth for 'scharr' function
ddepth = -1 #this should give the return image equal depth

img = cv2.imread('splash.jpg') # importing the image to be read from
# this directory, for simplicity

img = cv2.GaussianBlur(img, (3,3),0) # calling the function from cv. img
# is the previous image and (3,3) seems to be the size. the point of
# the function is to smooth the image to reduce noise.

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)# the function returns a
# colour gray, greyscale of the image.


# time for the gradient in the x-direction
grad_x = cv2.Sobel(gray, ddepth, 1,0, ksize=3, scale=scale, delta=delta, borderType=cv2.BORDER_DEFAULT)
# grad_x = cv2.Scharr(gray,ddepth, 1,0)
#now for y
grad_y = cv2.Sobel(gray, ddepth, 0,1, ksize=3, scale=scale, delta=delta, borderType=cv2.BORDER_DEFAULT)
# grad_y = cv2.Scharr(gray, ddepth, 0, 1)

abs_grad_x = cv2.convertScaleAbs(grad_x) #converting back to uint8
abs_grad_y = cv2.convertScaleAbs(grad_y)

dst = cv2.addWeighted(abs_grad_x, 0.5, abs_grad_y, (0.5), 0)
#dst = cv2.add(abs_grad_x. abs_grad_y)

cv2.imshow('dst', dst)
cv2.waitKey(0)
cv2.DestroyAllWindows()

最佳答案

您必须启用X11转发才能打开从远程主机到本地计算机的窗口。如果使用腻子,请转到“腻子配置”>“连接”>“X11”,然后选中“启用X11转发”。

如果您通过ssh连接槽,只需在命令中添加-X标志即可。ssh -X username@remote-host.com
神秘的输出

init done
opengl support available

由开发人员留在那儿(我猜是一个小错误),并在程序中执行cv::imshow(..)时随时打印。

关于python-2.7 - 我的opencv python程序显示看似期望的短语,但既不终止也不允许进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24613730/

相关文章:

python - Tkinter 用背景颜色填充整行

c++ - solvePnP 返回错误结果

c++ - GLEW + cmake 链接失败 "undefined reference to symbol glDrawElements"+ "DSO missing from command line"

python - 根据字典内的键值对将字典列表拆分为列表长度的列表列表

python - 未命名的 Python 对象具有相同的 id

python-2.7 - 如何将 python Tkinter 桌面应用程序转换为 Web 应用程序

python - Unix 终端截屏转文本

c# - InputArray 作为 Emgu CV 中的参数

OpenGL/GLU : Is there a built-in function for drawing circles?

c++ - 没有实例化的属性除数?