python学习资料整理


[1] The Python Tutorial

[2] Numpy Quick Start Tutorial

[3] Python-OpenCV

[4] http://www.learnpython.org/en/Welcome


如果一个python(a.py)文件被执行,变量__name__被赋值为"__main__"

def print1():
    print("this is a function")
def print2():
    print("this is also a function")

def main():
    print1()
    print2()

if __name__ == '__main__':
    main()

$ python a.py
this is a function
this is also a function


如果一个python(a.py)文件被import,其变量__name__被赋值为"a",即文件名称。

# a.py
import b

# b.py
print "Hello World from %s!" % __name__

if __name__ == '__main__':
    print "Hello World again from %s!" % __name__

$ python a.py
Hello World from b!

$ python b.py
Hello World from __main__!
Hello World again from __main__!

from py1 import *
可以直接调用py1里的函数


Opencv3.X 的mat与python的numpy是兼容的,需要注意的是其维度的顺序需要调整一下,cv2就可以处理numpy格式的图像文件。

def extract_data():
	with h5py.File('make3d_dataset_f460.mat','r') as f:
		images = f['make3d_dataset_fchange/images'][:]

	image_num = len(images)
	print images.shape
	for i in range(image_num):
		img = images[i,...].transpose((2, 1, 0))
		cv2.imshow('image', img)
		img = img*255
		img = img.astype('uint8')
		cv2.imwrite(file, img)
		cv2.waitKey(10000)



持续更新中。。。

你可能感兴趣的:(python学习资料整理)