我想使用Python执行一些基本的机器视觉任务,我想知道在哪里可以找到帮助我入门的教程.
据我所知,唯一一个用于机器视觉的Python免费库是PyCV(显然是OpenCV的包装器),但我找不到任何合适的教程.
我的主要任务是从FireWire获取图像.在不同区域中分割图像.然后对每个区域进行统计,以确定像素区域和质心.
以前,我使用过Matlab的Image Processing Tootlbox没有任何问题.我希望在Python中找到等价的函数是graythresh,regionprops和gray2ind.
谢谢!
是否可以在不使用if/else语句的情况下中断使用execfile函数调用的Python脚本的执行?我试过了exit(),但它不允许main.py完成.
# main.py
print "Main starting"
execfile("script.py")
print "This should print"
# script.py
print "Script starting"
a = False
if a == False:
# Sanity checks. Script should break here
# <insert magic command>
# I'd prefer not to put an "else" here and have to indent the rest of the code
print "this should not print"
# lots of lines below
Run Code Online (Sandbox Code Playgroud) 有没有更好的方法可以找到哪个X给了我在SciPy中寻找的Y?我刚开始使用SciPy,我对每个功能都不太熟悉.
import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
x = [70, 80, 90, 100, 110]
y = [49.7, 80.6, 122.5, 153.8, 163.0]
tck = interpolate.splrep(x,y,s=0)
xnew = np.arange(70,111,1)
ynew = interpolate.splev(xnew,tck,der=0)
plt.plot(x,y,'x',xnew,ynew)
plt.show()
t,c,k=tck
yToFind = 140
print interpolate.sproot((t,c-yToFind,k)) #Lowers the spline at the abscissa
Run Code Online (Sandbox Code Playgroud) 我已经注意到我的源代码控制使用ConfigParser生成的输出文件的内容永远不会以相同的顺序.有时,即使没有对值进行任何修改,部分也会更改部分内的位置或选项.
有没有办法在配置文件中对事物进行排序,这样我每次启动应用程序时都不必进行微不足道的更改?
如果您的主要选择标准是:您在汽车嵌入式系统中使用什么串行通信总线:
它不会传输大量数据,但需要定期高速传输(100 - 500 Hz).我发现如果你的地线有噪音,RS-232就不够可靠了.CAN总线似乎很有趣,但我没有经验.
我们目前对AVR AT90CAN128微控制器的组合感兴趣.
我试图评估我的界面的一个文本框中的字符串是否是一个数字(即不是文本或其他任何东西).在Python中,有一个名为isdigit()的方法,如果字符串只包含数字(没有负号或小数点),则返回True.如果我的字符串是一个有理数字(ex:1.25),还有另一种方法可以评估.
示例代码:
if self.components.txtZoomPos.text.isdigit():
step = int(self.components.txtZoomPos.text)
Run Code Online (Sandbox Code Playgroud) 我的应用程序有一个按钮,使用execfile动态执行python脚本.如果我在脚本中定义一个函数(例如spam())并尝试在另一个函数中使用该函数(例如eggs()),我会收到此错误:
NameError: global name 'spam' is not defined
Run Code Online (Sandbox Code Playgroud)
从eggs()中调用spam()函数的正确方法是什么?
#mainprogram.py
class mainprogram():
def runme(self):
execfile("myscript.py")
>>> this = mainprogram()
>>> this.runme()
# myscript.py
def spam():
print "spam"
def eggs():
spam()
eggs()
Run Code Online (Sandbox Code Playgroud)
此外,我似乎无法从脚本中的主应用程序执行方法.即
#mainprogram.py
class mainprogram():
def on_cmdRunScript_mouseClick( self, event ):
execfile("my2ndscript.py")
def bleh():
print "bleh"
#my2ndscript.py
bleh()
Run Code Online (Sandbox Code Playgroud)
错误是:
NameError: name 'bleh' is not defined
Run Code Online (Sandbox Code Playgroud)
从my2ndscript.py调用bleh()的正确方法是什么?
编辑:更新了第一期
在下面的代码(灵感来自这个片段),我用一个单一的事件处理程序buttonClick来改变窗口的标题.目前,我需要评估事件的Id是否与按钮的Id相对应.如果我决定添加50个按钮而不是2个,则此方法可能会变得很麻烦.有一个更好的方法吗?
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, 'wxBitmapButton',
pos=(300, 150), size=(300, 350))
self.panel1 = wx.Panel(self, -1)
self.button1 = wx.Button(self.panel1, id=-1,
pos=(10, 20), size = (20,20))
self.button1.Bind(wx.EVT_BUTTON, self.buttonClick)
self.button2 = wx.Button(self.panel1, id=-1,
pos=(40, 20), size = (20,20))
self.button2.Bind(wx.EVT_BUTTON, self.buttonClick)
self.Show(True)
def buttonClick(self,event):
if event.Id == self.button1.Id:
self.SetTitle("Button 1 clicked")
elif event.Id == self.button2.Id:
self.SetTitle("Button 2 clicked")
application = wx.PySimpleApp()
window = MyFrame()
application.MainLoop()
Run Code Online (Sandbox Code Playgroud) 之前已经问过其他语言的这个问题:Python,PHP和JavaScript.
我想知道是否可以在C中执行此操作.我试图在执行期间的某个时刻获取我的函数中的所有变量的快照,然后在稍后的时间点将其与另一个快照进行比较.
编辑
快照可以是范围内所有变量及其当前值的列表.我可以手工编写代码,但我想知道是否有更快的方法.
我刚刚安装了Python 3.0的第一个候选版本,并在输入后输入了以下错误:
>>> help('modules foo')
Run Code Online (Sandbox Code Playgroud)
[...] LookupError: unknown encoding: uft-8
请注意,它表示uft -8而不是utf -8
这是py3k特定的错误还是我的错误配置?我在这个法语区域设置Windows XP SP3机器上没有安装任何其他版本的Python.
编辑
如何在代码中打破一个长的字符串字符串并使字符串与其余代码一起缩进?PEP 8对此案例没有任何示例.
正确的ouptut但奇怪的缩进:
if True:
print "long test long test long test long test long \
test long test long test long test long test long test"
>>> long test long test long test long test long test long test long test long test long test long test
Run Code Online (Sandbox Code Playgroud)
输出错误,但在代码中看起来更好:
if True:
print "long test long test long test long test long \
test long test long test long test long test long test"
>>> long test long test …Run Code Online (Sandbox Code Playgroud) python ×9
string ×2
c ×1
can-bus ×1
class ×1
configparser ×1
events ×1
execfile ×1
flow-control ×1
matlab ×1
namespaces ×1
numpy ×1
python-3.x ×1
scipy ×1
scope ×1
serial-port ×1
wxpython ×1