【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 ...
随机推荐
- os内存使用管理之unix-AIX篇
os内存使用管理之unix-AIX篇 未完待补充.....
- Delphi中多标签页面的实现
unit uMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- Windows Azure入门教学系列 (二):部署第一个Web Role程序
本文是Windows Azure入门教学的第二篇文章. 在第一篇教学中,我们已经创建了第一个Web Role程序.在这篇教学中,我们将学习如何把该Web Role程序部署到云端. 注意:您需要购买Wi ...
- 北京出dell s2740显示器 1900 - V2EX
水木社区归档站 北京出dell s2740显示器 1900 - V2EX 北京出dell s2740显示器 1900 By kekex · 6 小时 6 分钟前 · 188 次点击 购于今年4月份 镜 ...
- QQ邮箱中转站文件即将过期时如何转存到微云
今天QQ邮箱提示我的中转站有个文件即将过期,然后我看看了那个文件然后我想永久保存这个文件,腾讯有个微云网盘(好像有10T),想知道能不能保存到微云已变永久保存 结果发现在文件中转站这个界面竟然没有续期 ...
- Java自注三进入
由于近期学的内容实际操作比較多,所以新的笔记就用代码为主体吧! 本回主要内容是输入,Java中主要用Scanner类和BufferedReader.整体来说不难,但有些细节能够总结,看代码: impo ...
- 显示出eclipse文件层次
看到图片中右边那个倒三角型符号没, 点一下,弹出个菜单,选package presentation->hierarachial 文件目录结构 flat 是包结构
- MFC如何生成一个可串行化的类
一.MFC允许对象在程序运行的整个过程中持久化的串行化机制 (1)串行化是指向持久化存储媒介(如一个磁盘文件)读或写对象的过程. (2)串行化用于在程序运行过程时或之后修复结构化数据(如C++类或结构 ...
- ubuntu环境ceph配置入门(一)
环境:ubuntu server 14.04 64bit,安装ceph版本号0.79 正常情况下应有多个主机,这里为了高速入门以一台主机为例,多台主机配置方式类似. 1. 配置静态IP及主机名 静态I ...
- 积累的VC编程小技巧之对话框
1.用鼠标移动基于对话框的无标题栏程序的简单方法 void CVCTestDlg::OnLButtonDown(UINT nFlags, CPoint point) { //一句话解决问题 ...