我试图从未校准的方法获得深度图.我可以通过SIFT方法和不同的对应点获得基本矩阵cv2.findFundamentalMat
.然后cv2.stereoRectifyUncalibrated
我可以得到整流矩阵.最后我可以cv2.warpPerspective
用来纠正和计算差异,但后者没有进行到一个好的深度图...值非常高,所以我想知道我是否必须使用warpPerspective
或我必须从单应矩阵计算旋转矩阵得到`stereoRectifyUncalibrated .
所以我不确定投影矩阵与单体矩阵的情况下获得的"stereoRectifyUncalibrated"`来纠正...
代码的一部分:
#Obtainment of the correspondent point with SIFT
sift = cv2.SIFT()
###find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(dst1,None)
kp2, des2 = sift.detectAndCompute(dst2,None)
###FLANN parameters
FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks=50)
flann = cv2.FlannBasedMatcher(index_params,search_params)
matches = flann.knnMatch(des1,des2,k=2)
good = []
pts1 = []
pts2 = []
###ratio test as per Lowe's paper
for i,(m,n) in enumerate(matches):
if m.distance …
Run Code Online (Sandbox Code Playgroud) 按照我之前的问题[1],我想对matplotlib的griddata
函数应用多处理.是否可以将网格数据分成4个部分,每4个核心分成一个?我需要这个以提高性能.
例如,尝试以下代码,尝试使用不同的值size
:
import numpy as np
import matplotlib.mlab as mlab
import time
size = 500
Y = np.arange(size)
X = np.arange(size)
x, y = np.meshgrid(X, Y)
u = x * np.sin(5) + y * np.cos(5)
v = x * np.cos(5) + y * np.sin(5)
test = x + y
tic = time.clock()
test_d = mlab.griddata(
x.flatten(), y.flatten(), test.flatten(), x+u, y+v, interp='linear')
toc = time.clock()
print 'Time=', toc-tic
Run Code Online (Sandbox Code Playgroud) 我试图用Matplotlib同时绘制3D平面和一些点.我没有错误只是不会出现这一点.我可以在不同时间绘制一些点和平面,但从不同时绘制.代码的一部分如下:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
point = np.array([1, 2, 3])
normal = np.array([1, 1, 2])
point2 = np.array([10, 50, 50])
# a plane is a*x+b*y+c*z+d=0
# [a,b,c] is the normal. Thus, we have to calculate
# d and we're set
d = -point.dot(normal)
# create x,y
xx, yy = np.meshgrid(range(10), range(10))
# calculate corresponding z
z = (-normal[0] * xx - normal[1] * yy - d) * 1. /normal[2]
# plot the …
Run Code Online (Sandbox Code Playgroud) 我试图获得校准棋盘的阈值.当我观察微型棋盘时,我无法直接检测到棋盘角落,因为有一些灰尘.我尝试了几种方法,而HoughLinesP似乎是最简单的方法.但结果不好,如何提高我的成绩?
import numpy as np
import cv2
img = cv2.imread('lines.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
print img.shape[1]
print img.shape
minLineLength=100
lines = cv2.HoughLinesP(image=edges,rho=0.02,theta=np.pi/500, threshold=10,lines=np.array([]), minLineLength=minLineLength,maxLineGap=100)
a,b,c = lines.shape
for i in range(a):
cv2.line(img, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (0, 0, 255), 3, cv2.LINE_AA)
cv2.imwrite('houghlines5.jpg',img)
Run Code Online (Sandbox Code Playgroud)
正如你在下图所示,我无法获得我的棋盘,线条被绘制在很多方向......(原始图片:https://s22.postimg.org/iq2b91xq9/droite_Image_00000.jpg)
我尝试使用matplotlib绘制频率直方图,但它不起作用,我不知道问题在哪里...
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
data = np.array([58.35, 71.83, 49.25, 38.89, 12.6, 58.34, 34.5, 11.6, 64.66, \
89.14, 101.84, 26.91, 38.74, 65.03, 35.23, 70.73, 54.52, 73.36, 74.35, \
60.54, 73.52, 24.58, 50.31, 55.63, 14.6, 53.64, 81.6])
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
n, bins, patches=ax.hist(data, 10, facecolor='green', alpha=0.75)
ax.yaxis.set_major_formatter(ticker.FuncFormatter(lambda y, pos: ('%.2f')%(y*1e-3)))
ax.set_ylabel('Frequency (000s)')
plt.show()
Run Code Online (Sandbox Code Playgroud)
错误消息的一部分:
sh: 1: dvipng: not found
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", …
Run Code Online (Sandbox Code Playgroud) 我正在努力depth map with OpenCV
.我可以获得它,但它是从左相机原点重建的,后者有一点倾斜,如图所示,深度"移位"(深度应该接近,没有水平渐变):
我想以零角度表达它,我尝试使用warp透视函数,如下所示,但我获得了一个空字段...
P = np.dot(cam,np.dot(Transl,np.dot(Rot,A1)))
dst = cv2.warpPerspective(depth, P, (2048, 2048))
Run Code Online (Sandbox Code Playgroud)
用:
#Projection 2D -> 3D matrix
A1 = np.zeros((4,3))
A1[0,0] = 1
A1[0,2] = -1024
A1[1,1] = 1
A1[1,2] = -1024
A1[3,2] = 1
#Rotation matrice around the Y axis
theta = np.deg2rad(5)
Rot = np.zeros((4,4))
Rot[0,0] = np.cos(theta)
Rot[0,2] = -np.sin(theta)
Rot[1,1] = 1
Rot[2,0] = np.sin(theta)
Rot[2,2] = np.cos(theta)
Rot[3,3] = 1
#Translation matrix on the X axis
dist = 0
Transl …
Run Code Online (Sandbox Code Playgroud) 我尝试为我的身材生成3个子图.它看起来很有效,但并不是完全一致的.如何在底部的数字和下面的数字之间有相同的宽度?
plt.close()
fig = plt.figure()
ax1 = plt.subplot(211)
ax1.plot(cycles,np.asarray(df_int),'wo',label='')
ax1.plot(cycles,np.asarray(df_proj),'k+',label='')
ax1.legend(loc=2)
#ax1.subplots_adjust(left=0.15)
ax1.set_ylim(0.001,0.004)
ax2 = plt.subplot(223)
i2=ax2.imshow(c,cmap=plt.cm.hot, vmin=-5, vmax=5);#plt.colorbar();plt.clim(-5,5)
cb2=plt.colorbar(i2,ax=ax2,ticks=[-5,0,5],fraction=0.046, pad=0.04,format='%.2f')
cb2.ax.tick_params(labelsize=12)
ax3 = plt.subplot(224)
i3=ax3.imshow(residue_proj,cmap=plt.cm.hot, vmin=-5, vmax=5);#plt.colorbar();plt.clim(-5,5);
cb3=plt.colorbar(i3,ax=ax3,ticks=[-5,0,5],fraction=0.046, pad=0.04,format='%.2f')
cb3.ax.tick_params(labelsize=12)
plt.savefig('test.png', dpi=500, bbox_inches='tight', pad_inches=0.1)
#plt.show()
Run Code Online (Sandbox Code Playgroud)
我有两个 numpy 数组“元素”和“节点”。我的目标是收集这些数组的一些数据。我需要用“节点”数组中包含的两个坐标替换最后两列的“元素”数据。这两个数组非常大,我必须自动化它。
这篇文章引用了一个旧帖子:用第二个数组的 2 个值替换数组的数据
不同之处在于数组非常大(元素:(3342558,5)和节点:(581589,4))并且以前的出路不起作用。
一个例子 :
import numpy as np
Elements = np.array([[1.,11.,14.],[2.,12.,13.]])
nodes = np.array([[11.,0.,0.],[12.,1.,1.],[13.,2.,2.],[14.,3.,3.]])
results = np.array([[1., 0., 0., 3., 3.],
[2., 1., 1., 2., 2.]])
Run Code Online (Sandbox Code Playgroud)
之前hpaulj提出的出路
e = Elements[:,1:].ravel().astype(int)
n=nodes[:,0].astype(int)
I, J = np.where(e==n[:,None])
results = np.zeros((e.shape[0],2),nodes.dtype)
results[J] = nodes[I,:1]
results = results.reshape(2,4)
Run Code Online (Sandbox Code Playgroud)
但是对于庞大的数组,此脚本不起作用:
DepreciationWarning: elementwise comparison failed; this will raise an error in the future
...
我正在使用 glob 来获取大量图像的图片对的名称。唯一的问题是我得到了绝对路径,我不想要那个,我只需要图片的名称。我能怎么做?
import glob
A=sorted(glob.glob('/media/test/A*.png'))
B=sorted(glob.glob('/media/test/B*.png'))
NumbSeq=len(A)
for i in range(0,NumbSeq):
print "\"%s\",\"%s\","%(A[i],B[i])
Run Code Online (Sandbox Code Playgroud)
我明白了 :
"/media/test/A170900_85495.460376.png","/media/test/B170900_85495.460376.png"
Run Code Online (Sandbox Code Playgroud)
我需要它 :
"A170900_85495.460376.png","B170900_85495.460376.png"
Run Code Online (Sandbox Code Playgroud) 我想知道是否有可能知道有多少行包含我的文件文本而不使用命令:
with open('test.txt') as f:
text = f.readlines()
size = len(text)
Run Code Online (Sandbox Code Playgroud)
我的文件非常庞大,所以很难使用这种方法......