【Python】Coding the Matrix:Week 5 Perspective Lab
这个Lab的内容光是说明就有7页之巨,我反复看了很久才看懂一点点,Lab主要完成的是从不同坐标系表示之间变换的方法。
原始的图片,从Camera basis的表示转换成WhiteBoard basis的表示
里面的Problem 3是难点,Problem 4我没有完成,因为还缺少之前的代码,暂时不写。
注意Problem 3中的vector h不能通过print(h)来获得,因为print会对浮点数进行四舍五入,导致答案错误。
#from image_mat_util import * from mat import Mat
from vec import Vec from solver import solve
from matutil import *
## Task 1
def move2board(v):
'''
Input:
- v: a vector with domain {'y1','y2','y3'}, the coordinate representation of a point q.
Output:
- A {'y1','y2','y3'}-vector z, the coordinate representation
in whiteboard coordinates of the point p such that the line through the
origin and q intersects the whiteboard plane at p.
'''
return Vec({'y1','y2','y3'}, {k:v[k]/v['y3'] for k in v.D}) ## Task 2
def make_equations(x1, x2, w1, w2):
'''
Input:
- x1 & x2: photo coordinates of a point on the board
- y1 & y2: whiteboard coordinates of a point on the board
Output:
- List [u,v] where u*h = 0 and v*h = 0
'''
domain = {(a, b) for a in {'y1', 'y2', 'y3'} for b in {'x1', 'x2', 'x3'}}
u = Vec(domain, {('y3','x1'):w1*x1,('y3','x2'):w1*x2,('y3','x3'):w1,('y1','x1'):-1*x1,('y1','x2'):-x2,('y1','x3'):-1})
v = Vec(domain, {('y3','x1'):w2*x1,('y3','x2'):w2*x2,('y3','x3'):w2,('y2','x1'):-1*x1,('y2','x2'):-x2,('y2','x3'):-1})
return [u, v] ## Task 3
x11=358
x21=36
w11=0
w21=0
x12=329
x22=597
w12=0
w22=1
x13=592
x23=157
w13=1
w23=0
x14=580
x24=483
w14=1
w24=1
[u1,v1]=make_equations(x11, x21, w11, w21)
[u2,v2]=make_equations(x12, x22, w12, w22)
[u3,v3]=make_equations(x13, x23, w13, w23)
[u4,v4]=make_equations(x14, x24, w14, w24)
w=Vec(u1.D,{('y1','x1'):1})
b=Vec(range(9),{8:1})
L=rowdict2mat([u1,v1,u2,v2,u3,v3,u4,v4,w])
h=solve(L,b)
H = Mat(({'y2', 'y3', 'y1'}, {'x1', 'x3', 'x2'}),h.f) ## Task 4
def mat_move2board(Y):
'''
Input:
- Y: Mat instance, each column of which is a 'y1', 'y2', 'y3' vector
giving the whiteboard coordinates of a point q.
Output:
- Mat instance, each column of which is the corresponding point in the
whiteboard plane (the point of intersection with the whiteboard plane
of the line through the origin and q).
'''
pass
【Python】Coding the Matrix:Week 5 Perspective Lab的更多相关文章
- 【Python】Coding the Matrix:Week 5: Dimension Homework 5
这一周的作业,刚压线写完.Problem3 没有写,不想证明了.从Problem 9 开始一直到最后难度都挺大的,我是在论坛上看过了别人的讨论才写出来的,挣扎了很久. Problem 9在给定的基上分 ...
- 【python】SQLAlchemy
来源:廖雪峰 对比:[python]在python中调用mysql 注意连接数据库方式和数据操作方式! 今天发现了个处理数据库的好东西:SQLAlchemy 一般python处理mysql之类的数据库 ...
- 【Python】内置数据类型
参考资料: http://sebug.net/paper/books/dive-into-python3/native-datatypes.html http://blog.csdn.net/hazi ...
- 【Python】 零碎知识积累 II
[Python] 零碎知识积累 II ■ 函数的参数默认值在函数定义时确定并保存在内存中,调用函数时不会在内存中新开辟一块空间然后用参数默认值重新赋值,而是单纯地引用这个参数原来的地址.这就带来了一个 ...
- 【Python】【BugList12】python自带IDLE执行print(req.text)报错:UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 93204-93204
[代码] # -*- coding:UTF-8 -*- import requests if __name__ == '__main__': target = 'https://unsplash.co ...
- 【Python】【内置函数】
[fromkeys()] -- coding: utf-8 -- python 27 xiaodeng python之函数用法fromkeys() fromkeys() 说明:用于创建一个新字典,以序 ...
- 【Python】-NO.98.Note.3.Python -【Python3 解释器、运算符】
1.0.0 Summary Tittle:[Python]-NO.98.Note.3.Python -[Python3 解释器] Style:Python Series:Python Since:20 ...
- 【Python】【容器 | 迭代对象 | 迭代器 | 生成器 | 生成器表达式 | 协程 | 期物 | 任务】
Python 的 asyncio 类似于 C++ 的 Boost.Asio. 所谓「异步 IO」,就是你发起一个 IO 操作,却不用等它结束,你可以继续做其他事情,当它结束时,你会得到通知. Asyn ...
- 【Python】无须numpy,利用map函数与zip(*)函数对数组转置(转)
http://blog.csdn.net/yongh701/article/details/50283689 在Python的numpy中,对类似array=[[1,2,3],[4,5,6],[7,8 ...
随机推荐
- 树——axure线框图部件库介绍
终于到最后一个组件的介绍了!到这里基础的应用应该算完成了! 1. 拖动树组件,到页面编辑区域 2.添加节点,可以添加子节点也可以在该节点的前后添加平级节点 3. 编辑节点图标 做好上面的那一步, ...
- 让程序在崩溃时体面的退出之Dump文件
在我的那篇<让程序在崩溃时体面的退出之CallStack>中提供了一个在程序崩溃时得到CallStack的方法.但是要想得到CallStack,必须有pdb文件的支持.但 ...
- <转载>如何解决子级用float浮动父级div高度不能自适应的问题
转载:http://www.kwstu.com/ArticleView/divcss_2013101582430202 解决子级对象使用css float浮动 而父级div不能自适应高度,不能被父级内 ...
- Redis核心解读:集群管理工具(Redis-sentinel)
Redis核心解读:集群管理工具(Redis-sentinel) - Redis - TechTarget数据库 Redis核心解读:集群管理工具(Redis-sentinel)
- 利用PS滤镜及图层叠加制作水墨荷花
水墨荷花制作思路并不复杂:把图片转为黑白,用滤镜等增加水墨纹理即可.不过在处理的时候还有很多细节需要处理,如图片的背景,水墨纹理控制范围等,这些需要自己慢慢摸索. 原图 最终效果 1.打开素材图片,把 ...
- C 函数 strstr 的高效实现
C函数库中有一个函数 strstr(char*, char*),它实现的是在一个原字符串中查找一个子串.假设找到这种一个子串,返回这个子串在原字符串中的起始位置,若没有找到这种一个子串.则 ...
- 医院API免费接口的公布
医院通网(http://hospital.yi18.net) 站点上站快两个月了,基本已经稳定,尽管还有非常多小bug,但还是不影响大局.抱着数据开放和共享的理念,医院大全API接口 (http:// ...
- Call Transaction 小节
采购订单: . CALL FUNCTION ‘ME_DISPLAY_PURCHASE_DOCUMENT’ EXPORTING i_ebeln = itab-ebeln EXCEPTIONS not_f ...
- Redis intset
Redis intset也非常简单.它是一个有序整数集合,实际上是一个有序数组,查找时二分查找,添加时可能需要内存挪动.唯一不同的是,它的整数类型是变动的,可以支持int16,int32,int64三 ...
- SRM 624 Building Heights DivI 解读
几乎相同的一标题.欲了解更多请参阅:http://community.topcoder.com/stat?c=problem_statement&pm=13211&rd=15857 思 ...