这个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的更多相关文章

  1. 【Python】Coding the Matrix:Week 5: Dimension Homework 5

    这一周的作业,刚压线写完.Problem3 没有写,不想证明了.从Problem 9 开始一直到最后难度都挺大的,我是在论坛上看过了别人的讨论才写出来的,挣扎了很久. Problem 9在给定的基上分 ...

  2. 【python】SQLAlchemy

    来源:廖雪峰 对比:[python]在python中调用mysql 注意连接数据库方式和数据操作方式! 今天发现了个处理数据库的好东西:SQLAlchemy 一般python处理mysql之类的数据库 ...

  3. 【Python】内置数据类型

    参考资料: http://sebug.net/paper/books/dive-into-python3/native-datatypes.html http://blog.csdn.net/hazi ...

  4. 【Python】 零碎知识积累 II

    [Python] 零碎知识积累 II ■ 函数的参数默认值在函数定义时确定并保存在内存中,调用函数时不会在内存中新开辟一块空间然后用参数默认值重新赋值,而是单纯地引用这个参数原来的地址.这就带来了一个 ...

  5. 【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 ...

  6. 【Python】【内置函数】

    [fromkeys()] -- coding: utf-8 -- python 27 xiaodeng python之函数用法fromkeys() fromkeys() 说明:用于创建一个新字典,以序 ...

  7. 【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 ...

  8. 【Python】【容器 | 迭代对象 | 迭代器 | 生成器 | 生成器表达式 | 协程 | 期物 | 任务】

    Python 的 asyncio 类似于 C++ 的 Boost.Asio. 所谓「异步 IO」,就是你发起一个 IO 操作,却不用等它结束,你可以继续做其他事情,当它结束时,你会得到通知. Asyn ...

  9. 【Python】无须numpy,利用map函数与zip(*)函数对数组转置(转)

    http://blog.csdn.net/yongh701/article/details/50283689 在Python的numpy中,对类似array=[[1,2,3],[4,5,6],[7,8 ...

随机推荐

  1. Mockito文档-单元测试技术

    Overview  Package   Class  Use  Tree  Deprecated  Index  Help     PREV CLASS   NEXT CLASS FRAMES     ...

  2. 为什么要用BitSet

    BitSet适用于一类型boolean判断,Java的BitSet在这类型判断中非常高效. 举例说明:在判断前2000万数字中素数个数的程序中,如果使用最基本的素数判断代码: package com; ...

  3. UVALive 2519 Radar Installation 雷达扫描 区间选点问题

    题意:在坐标轴中给出n个岛屿的坐标,以及雷达的扫描距离,要求在y=0线上放尽量少的雷达能够覆盖全部岛屿. 很明显的区间选点问题. 代码: /* * Author: illuz <iilluzen ...

  4. Matlab图像处理系列2———空间域平滑滤波器

    注:本系列来自于图像处理课程实验,用Matlab实现最主要的图像处理算法 本文章是Matlab图像处理系列的第二篇文章.介绍了空间域图像处理最主要的概念----模版和滤波器,给出了均值滤波起和中值滤波 ...

  5. iOS开发技巧 -- 复用代码片段

    如果你是一位开发人员在开发过程中会发现有些代码无论是在同一个工程中还是在不同工程中使用率会很高,有经验的人会直接封装在一个类里,或者写成一个宏定义或者把这些代码收集起来,下次直接使用,或者放到xcod ...

  6. 每天一个JavaScript实例-推断图片是否载入完毕

    <!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  7. script:查看历史sql执行信息

    script:查看历史sql执行信息 SELECT *     FROM (SELECT '1.v$sql'||'实例号:'||GV$SQL.inst_id source,               ...

  8. Go成功的项目

    nsq:bitly开源的消息队列系统,性能非常高,目前他们每天处理数十亿条的消息docker:基于lxc的一个虚拟打包工具,能够实现PAAS平台的组建.packer:用来生成不同平台的镜像文件,例如V ...

  9. Delphi 中TWebBrowser的扩展控件TExWebBrowser

    主要扩展了3D界面.右键菜单.是否显示图片.是否支持JAVA等功能. 代码如下: unit ExtWebBrowser; interface uses Windows, SysUtils, Class ...

  10. 开源yYmVc项目 v 0.2 版本号介绍

    项目地址:https://code.csdn.net/hacke2/yymvc 本版本号主要实现下面几点功能: 1.框架入口基于过滤器统一实现,action后缀动态配置 2.action配置模仿str ...