相移条纹图案

Phase shifted fringe pattern

我已经为像这样的结构光测试创建了一个条纹图案 (Binary pattern) 使用代码片段在 python

中生成 pwm 信号
import numpy as np
import cv2

amp=float(input('fringe amplitude:'))
t=float(input('time period:'))
c=int(input('cycle time:'))
dt=1
xpix=np.arange(0,c*t,dt)
ypix=np.zeros_like(xpix)
n=t/dt

i=0
while i*dt< c*t:
    if (i % n)/n < amp/100.0:
        ypix[i]=1
    i=i+1

A =255*np.tile(ypix,(1140,1))
print(A)
i= input('enter value:')
cv2.imwrite('C:\Users\newimg'+str(i)+'.bmp', A)

我想将它们相移每个信号时间周期的 1/3,以创建两个新的移位图像。有没有办法编辑此代码来执行此操作或更好/更容易使用的选项?

关于你的代码的一些事情我并不完全清楚,但是如果你想移动模式,你应该简单地添加一个定义移动多少的变量,然后用该变量偏移你的轴,就像这样:

import numpy as np
import cv2

amp=float(input('fringe amplitude:'))
t=float(input('time period:'))
c=int(input('cycle time:'))

# this is the shift variable
shift = int(input('shift amount'))

dt=1
xpix=np.arange(0,c*t,dt)
ypix=np.zeros_like(xpix)
n=t/dt

i=0
while i*dt< c*t:
    # Here we offset i by the shift variable.
    # Because we are summing, we are moving everything left by $shift pixels
    # If you want to move right simply insert a negative value in shift
    if ((i + shift) % n)/n < amp/100.0:
        ypix[i]=1
    i=i+1

A =255*np.tile(ypix,(1140,1))
print(A)
i= input('enter value:')
cv2.imwrite('newimg'+str(i)+'.bmp', A)