2016-03-24 00:49:56 +08:00
|
|
|
#!/usr/bin/env python3.5
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
from numba import jit
|
2016-04-04 19:10:49 +08:00
|
|
|
import logging
|
2016-03-24 00:49:56 +08:00
|
|
|
|
|
|
|
from artiq.protocols.remote_exec import simple_rexec_server_loop
|
|
|
|
|
|
|
|
|
|
|
|
@jit(nopython=True)
|
2016-04-02 22:44:52 +08:00
|
|
|
def compute_picture(r, img_w, img_h,
|
2016-03-24 00:49:56 +08:00
|
|
|
gaussian_w, gaussian_h,
|
|
|
|
gaussian_cx, gaussian_cy,
|
|
|
|
noise_level):
|
|
|
|
for y in range(img_h):
|
|
|
|
for x in range(img_w):
|
|
|
|
ds = ((gaussian_cx-x)/gaussian_w)**2
|
|
|
|
ds += ((gaussian_cy-y)/gaussian_h)**2
|
|
|
|
r[x, y] = np.exp(-ds/2) + noise_level*np.random.random()
|
|
|
|
|
|
|
|
|
|
|
|
class CameraSimulation:
|
|
|
|
def __init__(self):
|
|
|
|
self.img_w = 320
|
|
|
|
self.img_h = 200
|
|
|
|
self.gaussian_w = 4
|
|
|
|
self.gaussian_h = 3
|
|
|
|
self.gaussian_cx = self.img_w//2
|
|
|
|
self.gaussian_cy = self.img_h//2
|
|
|
|
self.noise_level = 0.1
|
|
|
|
|
|
|
|
def set_gaussian_width(self, wx, wy=None):
|
|
|
|
if wy is None:
|
|
|
|
wy = wx
|
|
|
|
self.gaussian_w = wx
|
|
|
|
self.gaussian_h = wy
|
|
|
|
|
|
|
|
def set_gaussian_center(self, x, y):
|
|
|
|
self.gaussian_cx = x
|
|
|
|
self.gaussian_cy = y
|
|
|
|
|
|
|
|
def set_noise_level(self, noise_level):
|
|
|
|
self.noise_level = noise_level
|
|
|
|
|
|
|
|
def get_picture(self):
|
|
|
|
r = np.empty((self.img_w, self.img_h))
|
2016-04-02 22:44:52 +08:00
|
|
|
compute_picture(r, self.img_w, self.img_h,
|
2016-03-24 00:49:56 +08:00
|
|
|
self.gaussian_w, self.gaussian_h,
|
|
|
|
self.gaussian_cx, self.gaussian_cy,
|
|
|
|
self.noise_level)
|
|
|
|
return r
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2016-04-04 19:10:49 +08:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
2016-03-24 00:49:56 +08:00
|
|
|
simple_rexec_server_loop("camera_sim", CameraSimulation(),
|
|
|
|
"::1", 6283)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|