reindent and some image tweeks
This commit is contained in:
147
camera.py
147
camera.py
@@ -24,6 +24,20 @@ Best regards
|
||||
Helge
|
||||
"""
|
||||
|
||||
# In [2]: np.array(range(20))
|
||||
# Out[2]:
|
||||
# array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
# 17, 18, 19])
|
||||
|
||||
# In [3]: np.array(range(20)).reshape(4,5)
|
||||
# Out[3]:
|
||||
# array([[ 0, 1, 2, 3, 4],
|
||||
# [ 5, 6, 7, 8, 9],
|
||||
# [10, 11, 12, 13, 14],
|
||||
# [15, 16, 17, 18, 19]])
|
||||
|
||||
# shape is (imgidx,h,w) w is the fast counting index
|
||||
|
||||
import logging
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
@@ -99,7 +113,7 @@ class epics_cam(object):
|
||||
imgSeq=self._sim['imgSeq']
|
||||
idx=self._sim['imgIdx']
|
||||
self._sim['imgIdx']=(idx + 1) % imgSeq.shape[0]
|
||||
_log.info('simulated idx:{}'.format(idx))
|
||||
#_log.debug('simulated idx:{}'.format(idx))
|
||||
self.pic=pic=imgSeq[idx]
|
||||
return pic
|
||||
try:
|
||||
@@ -200,30 +214,54 @@ class epics_cam(object):
|
||||
|
||||
def sim_gen(self,sz=(1500,1000),t=100,mode=0):
|
||||
'generate simulation data'
|
||||
_log.info('generate simulation images, mode:{}...'.format(mode))
|
||||
w,h=sz
|
||||
self._imgSeq=imgSeq=np.ndarray(shape=(t,h,w),dtype=np.uint16)
|
||||
x = np.linspace(-5, 5, w)
|
||||
y = np.linspace(-5, 5, h)
|
||||
# full coordinate arrays
|
||||
xx, yy = np.meshgrid(x, y)
|
||||
if mode==0:
|
||||
_log.info('generate {} pulsing wases simulation images, mode:{}...'.format(t,mode))
|
||||
w,h=sz
|
||||
imgSeq=np.ndarray(shape=(t,h,w),dtype=np.uint16)
|
||||
x = np.linspace(-5, 5, w)
|
||||
y = np.linspace(-5, 5, h)
|
||||
# full coordinate arrays
|
||||
xx, yy = np.meshgrid(x, y)
|
||||
|
||||
for i in range(t):
|
||||
#imgSeq[i,:,:] = 100*np.sqrt(np.sin(xx+.1*i)**2 + np.sin(yy+.01*i)**2)#+xx*t+yy*t)
|
||||
#imgSeq[i,:,:] = 100*np.sqrt(np.sin(xx+.1*i)**2 + np.sin((1+.1*np.sin(.2*i))*yy+.001*i**2)**2)#+xx*t+yy*t)
|
||||
#imgSeq[i,:,:] = 100*np.sqrt(np.sin(xx+2*np.sin(i/t*2*np.pi))**2 + np.sin(yy)**2)
|
||||
px=2*np.sin(i/t*2*np.pi)
|
||||
fx=1
|
||||
py=2*np.sin(i/t*2*np.pi)
|
||||
fy=1+.3*np.sin(i/t*2*np.pi*2)
|
||||
imgSeq[i,:,:] = 100*np.sqrt(np.sin(xx*fx+px)**2 + np.sin(yy*fy+py)**2)
|
||||
#np.random.bytes(100)
|
||||
wr=w//4
|
||||
hr=h//4
|
||||
imgSeq[:,0:hr,0:wr]+=np.random.randint(0,100,(t,hr,wr),dtype=np.uint16)
|
||||
elif mode==1:
|
||||
import glob,PIL.Image
|
||||
path='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/SwissMX/simCamImg/*.png'
|
||||
_log.info('generate simulation images:{}...'.format(path))
|
||||
glb=glob.glob(path)
|
||||
img = PIL.Image.open(glb[0])
|
||||
sz=img.size # (w,h)
|
||||
imgSeq=np.ndarray(shape=(len(glb),sz[1],sz[0]),dtype=np.uint8) # shape is (n,h,w)
|
||||
for i,fn in enumerate(glb):
|
||||
img=PIL.Image.open(fn)
|
||||
assert(img.mode=='L') # 8 bit grayscale
|
||||
assert(sz==img.size)
|
||||
imgSeq[i,:,:]=np.array(img.getdata()).reshape(sz[::-1])
|
||||
f=np.array(((0,0,0,0,0),
|
||||
(0,1,1,1,0),
|
||||
(0,1,0,0,0),
|
||||
(0,1,1,0,0),
|
||||
(0,1,0,0,0),
|
||||
(0,0,0,0,0),),imgSeq.dtype)
|
||||
imgSeq[i,0:6,0:5]=f*255
|
||||
|
||||
|
||||
|
||||
for i in range(t):
|
||||
#imgSeq[i,:,:] = 100*np.sqrt(np.sin(xx+.1*i)**2 + np.sin(yy+.01*i)**2)#+xx*t+yy*t)
|
||||
#imgSeq[i,:,:] = 100*np.sqrt(np.sin(xx+.1*i)**2 + np.sin((1+.1*np.sin(.2*i))*yy+.001*i**2)**2)#+xx*t+yy*t)
|
||||
#imgSeq[i,:,:] = 100*np.sqrt(np.sin(xx+2*np.sin(i/t*2*np.pi))**2 + np.sin(yy)**2)
|
||||
px=2*np.sin(i/t*2*np.pi)
|
||||
fx=1
|
||||
py=2*np.sin(i/t*2*np.pi)
|
||||
fy=1+.3*np.sin(i/t*2*np.pi*2)
|
||||
imgSeq[i,:,:] = 100*np.sqrt(np.sin(xx*fx+px)**2 + np.sin(yy*fy+py)**2)
|
||||
#np.random.bytes(100)
|
||||
wr=w//4
|
||||
hr=h//4
|
||||
imgSeq[:,0:hr,0:wr]+=np.random.randint(0,100,(t,hr,wr),dtype=np.uint16)
|
||||
self._sim['imgSeq']=imgSeq
|
||||
self._sim['imgIdx']=0
|
||||
_log.info('dome')
|
||||
_log.info('done-> shape:{} dtype:{}'.format(imgSeq.shape,imgSeq.dtype))
|
||||
|
||||
def set_transformations(self,*args):
|
||||
_log.error('OLD FUNCTION NOT IMPLEMENTED {}'.format(args))
|
||||
@@ -232,7 +270,9 @@ class epics_cam(object):
|
||||
if __name__ == "__main__":
|
||||
import time, os, PIL.Image, platform, subprocess
|
||||
import argparse
|
||||
logging.basicConfig(level=logging.DEBUG,format='%(levelname)s:%(module)s:%(lineno)d:%(funcName)s:%(message)s ')
|
||||
logging.basicConfig(level=logging.DEBUG,format='%(name)s:%(levelname)s:%(module)s:%(lineno)d:%(funcName)s:%(message)s ')
|
||||
logging.getLogger('PIL').setLevel(logging.INFO)
|
||||
|
||||
|
||||
def default_app_open(file):
|
||||
if platform.system() == 'Darwin': # macOS
|
||||
@@ -248,6 +288,7 @@ if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--ui", "-u", help="qt test", type=int, default=0)
|
||||
parser.add_argument("--sim", "-s", help="simulation mode", type=int, default=None)
|
||||
parser.add_argument("--delay", "-d", help="delay in simulation mode", type=float, default=None)
|
||||
parser.add_argument("--prefix","-p",help="PV prefix for images: default=%(default)s",type=str,default="SARES30-CAMS156-SMX-OAV",)
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -328,7 +369,11 @@ if __name__ == "__main__":
|
||||
(0,1,0,0,0),
|
||||
(0,0,0,0,0),),pic.dtype)
|
||||
pic[0:6,0:5]=f*pic.max()
|
||||
imv.setImage(pic, autoRange=False, autoLevels=False)
|
||||
if args.ui==1:
|
||||
img.setImage(pic)
|
||||
else:
|
||||
imv.setImage(pic, autoRange=False, autoLevels=False)
|
||||
|
||||
|
||||
def new_frame_sim_cb(self,arl=False):
|
||||
imgSeq =self._sim['imgSeq']
|
||||
@@ -338,9 +383,15 @@ if __name__ == "__main__":
|
||||
self._sim['imgIdx']=(idx+1) % imgSeq.shape[0]
|
||||
#_log.info('simulated idx:{}'.format(idx))
|
||||
pic = imgSeq[idx]
|
||||
imv.setImage(pic, autoRange=arl, autoLevels=arl)
|
||||
if args.ui==1:
|
||||
img.setImage(pic)
|
||||
else:
|
||||
imv.setImage(pic, autoRange=arl, autoLevels=arl)
|
||||
|
||||
QtCore.QTimer.singleShot(1, self.new_frame_sim_cb)
|
||||
if args.delay:
|
||||
QtCore.QTimer.singleShot(int(1000*args.delay), self.new_frame_sim_cb)
|
||||
else:
|
||||
QtCore.QTimer.singleShot(0, self.new_frame_sim_cb)
|
||||
now = ptime.time()
|
||||
fps2 = 1.0 / (now - udt)
|
||||
self._sim['updateTime'] = now
|
||||
@@ -358,13 +409,34 @@ if __name__ == "__main__":
|
||||
|
||||
app = QtGui.QApplication([])
|
||||
|
||||
## Create window with ImageView widget
|
||||
win = QtGui.QMainWindow()
|
||||
win.resize(800,800)
|
||||
imv = pg.ImageView()
|
||||
win.setCentralWidget(imv)
|
||||
win.show()
|
||||
win.setWindowTitle('pyqtgraph example: ImageView')
|
||||
if args.ui==1:
|
||||
win = pg.GraphicsLayoutWidget()
|
||||
win.show() ## show widget alone in its own window
|
||||
win.setWindowTitle('pyqtgraph example: ImageItem')
|
||||
view = win.addViewBox(invertY=True)
|
||||
|
||||
## lock the aspect ratio so pixels are always square
|
||||
view.setAspectLocked(True)
|
||||
|
||||
## Create image item https://pyqtgraph.readthedocs.io/en/latest/graphicsItems/imageitem.html
|
||||
img = pg.ImageItem(border='g')
|
||||
#tr = QtGui.QTransform() # prepare ImageItem transformation:
|
||||
#tr.scale(6.0, 3.0) # scale horizontal and vertical axes
|
||||
#tr.translate(-1.5, -1.5) # move 3x3 image to locate center at axis origin
|
||||
#img.setTransform(tr) # assign transform
|
||||
view.addItem(img)
|
||||
|
||||
## Set initial view bounds
|
||||
view.setRange(QtCore.QRectF(0, 0, 600, 600))
|
||||
else:
|
||||
## Create window with ImageView widget
|
||||
win = QtGui.QMainWindow()
|
||||
win.resize(800,800)
|
||||
imv = pg.ImageView()
|
||||
win.setCentralWidget(imv)
|
||||
win.show()
|
||||
win.setWindowTitle('pyqtgraph example: ImageView')
|
||||
|
||||
|
||||
## Display the data and assign each frame a time value from 1.0 to 3.0
|
||||
cam = UIcamera(prefix=args.prefix)
|
||||
@@ -383,10 +455,11 @@ if __name__ == "__main__":
|
||||
cam._sim['updateTime'] = ptime.time()
|
||||
cam.new_frame_sim_cb(arl=True)
|
||||
|
||||
## Set a custom color map
|
||||
colors = [(0, 0, 0),(45, 5, 61),(84, 42, 55),(150, 87, 60),(208, 171, 141),(255, 255, 255)]
|
||||
cmap = pg.ColorMap(pos=np.linspace(0.0, 1.0, 6), color=colors)
|
||||
imv.setColorMap(cmap)
|
||||
if args.ui==2:
|
||||
## Set a custom color map
|
||||
colors = [(0, 0, 0),(45, 5, 61),(84, 42, 55),(150, 87, 60),(208, 171, 141),(255, 255, 255)]
|
||||
cmap = pg.ColorMap(pos=np.linspace(0.0, 1.0, 6), color=colors)
|
||||
imv.setColorMap(cmap)
|
||||
|
||||
## Start Qt event loop unless running in interactive mode.
|
||||
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
||||
|
||||
Reference in New Issue
Block a user