我想计算我的相机在世界坐标中的位置.这应该相当容易,但我没有得到我期望的结果.我相信我已经阅读了有关此主题的所有内容,但我的代码无效.这是我做的:
我有一个相机看着一个区域.
1)我画了一张该地区的地图.
2)我通过使用在我的地图上将4个图像点匹配到4个点来计算单应性 cv2.getPerspectiveTransform
3)H homography将每个世界坐标转换为摄像机坐标; 这是正常的
4)为了计算相机矩阵我遵循这个:
translation = np.zeros((3,1))
translation[:,0] = homography[:,2]
rotation = np.zeros((3,3))
rotation[:,0] = homography[:,0]
rotation[:,1] = homography[:,1]
rotation[:,2] = np.cross(homography[0:3,0],homography[0:3,1])
cameraMatrix = np.zeros((3,4))
cameraMatrix[:,0:3] = rotation
cameraMatrix[:,3] = homography[:,2]
cameraMatrix = cameraMatrix/cameraMatrix[2][3] #normalize the matrix
Run Code Online (Sandbox Code Playgroud)
5)根据这个,相机的位置应该这样计算:
x,y,z = np.dot(-np.transpose(rotation),translation)
Run Code Online (Sandbox Code Playgroud)
我得到的坐标是完全错误的.我想这个问题应该在步骤4或5的某个地方.我的方法有什么问题?
我想在PyS60中为我的诺基亚手机写一个小型蓝牙服务器应用程序.它需要能够发送对客户端请求的响应,并能够将数据推送到客户端.
选项1:如果我使用socket.recv(1024)
,程序会等到收到某些内容,因此服务器无法将数据推送到客户端.用于S60实现的Python缺少该socket.settimeout()
方法,因此我无法编写正确的非阻塞代码.
oprion 2:socket.makefile()
方法看起来不错,但无法使其发挥作用.当我更换为conn.recv(1024)
to时fd = socket.makefile() fd.readline()
,它没有读到任何东西.
选项3:查看select()
函数,但没有运气.当我改变了conn.recv()
对r,w,e = select.select([conn],[],[])
像它已经建议客户甚至不连接.它挂在"等待客户......".奇怪...
我知道有很好的服务器实现和异步API-s,但我只需要一个非常基本的东西.提前致谢!
这就是我所拥有的:
sock = btsocket.socket(btsocket.AF_BT, btsocket.SOCK_STREAM)
channel = btsocket.bt_rfcomm_get_available_server_channel(sock)
sock.bind(("", channel))
sock.listen(1)
btsocket.bt_advertise_service(u"name", sock, True, btsocket.RFCOMM)
print "Waiting for the client..."
conn, client_mac = sock.accept()
print "connected: " + client_mac
while True:
try:
data = conn.recv(1024)
if len(data) != 0:
print "received [%s]" % data
if data.startswith("something"): conn.send("something\r\n")
else:
conn.send("some other …
Run Code Online (Sandbox Code Playgroud) phaseCorrelate似乎是OpenCV Python包装器的一个未记录的函数.C++函数的doc就在这里.
当我从Python调用该函数时,我收到以下错误:
cv2.error: ..\..\..\src\opencv\modules\imgproc\src\phasecorr.cpp:495: error: (-215) src1.type() == CV_32FC1 || src1.type() == CV_64FC1
Run Code Online (Sandbox Code Playgroud)
每个OpenCV 2函数都使用numpy数组,我怀疑这个函数是从旧的包装器中保留的.也许我需要在调用函数之前将numpy数组转换为CvMats?我怎么做?
我正在使用OpenCV的Python绑定,它真的很棒.但是,C++版本中的函数缺少Python绑定,BackgroundSubstractorMOG2以及许多特征检测算法.从Python调用它们最简单的方法是什么?
我正在编写一个简单的套接字服务器,我想跟踪客户端状态(身份验证和其他内容)。每次调用 handle_read() 时,我对该特定客户端一无所知。如果我知道客户的 ID 或其他东西,那会有所帮助。这是我到目前为止所拥有的:
import asyncore
import socket
class EchoHandler(asyncore.dispatcher_with_send):
def handle_read(self):
data = self.recv(8192)
self.send(data)
class EchoServer(asyncore.dispatcher):
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind((host, port))
self.listen(5)
def handle_accept(self):
pair = self.accept()
if pair is None:
pass
else:
sock, addr = pair
print 'Incoming connection from %s' % repr(addr)
handler = EchoHandler(sock)
server = EchoServer('localhost', 8080)
asyncore.loop()
Run Code Online (Sandbox Code Playgroud) 我正在使用GPS开发一个Android应用程序.我想实现一个功能,显示用户在1/5/15分钟内的平均速度.类似于unix上的CPU负载.我可以通过累计逐秒计算的距离并将其除以经过的时间来轻松计算平均值,但我想不出计算移动平均线的聪明方法.
显然,我可以通过每秒将最后一个位置和当前位置之间的距离放在一个数组中,同时删除最旧的值来完成id.
我正在寻找一种巧妙的方法.
我在python中编写套接字服务器.它需要向客户端模块发送确认.从协议描述引用:
"[...]服务器应该确定它是否接受来自该模块的数据.如果是,服务器将回复模块01,如果不是00."
我在python中实现了这个:
connection.send('01')
Run Code Online (Sandbox Code Playgroud)
它不起作用,所以我检查了服务器的java实现:
byte[] answer = {
0x01};
out.write(answer);
out.flush();
Run Code Online (Sandbox Code Playgroud)
我想知道它是否相同?System.out.write(回答); 似乎没有输出到控制台的东西.