sorted out some stuff with the motion lib package
This commit is contained in:
@@ -74,12 +74,10 @@ pip install -r requirements.txt
|
||||
```
|
||||
```bash
|
||||
#!/bin/bash
|
||||
set -e
|
||||
cd "lib"
|
||||
# Clone the repo
|
||||
#git clone https://gitea.psi.ch/berti_r/Motion_lib.git
|
||||
|
||||
pwd
|
||||
|
||||
# Install package directly from GitHub
|
||||
pip install https://gitea.psi.ch/berti_r/Motion_lib/raw/branch/main/dist/mfl-0.0.3.tar.gz
|
||||
|
||||
|
||||
```
|
||||
|
||||
@@ -45,7 +45,8 @@ import numpy as np
|
||||
from image_analysis import image_center_of_mass
|
||||
from utils import get_datestr, get_timestr
|
||||
import ad
|
||||
from metrology_functions import init_nr_of_cycles, safe_meas_settings, init_image_processing_yes_no, __process_img
|
||||
from metrology_functions import init_nr_of_cycles, safe_meas_settings, init_image_processing_yes_no
|
||||
from image_analysis import __process_img
|
||||
import myutility as myu
|
||||
import cv2
|
||||
import json
|
||||
|
||||
Binary file not shown.
@@ -10,6 +10,10 @@ on this image are provided.
|
||||
import matplotlib.pyplot as plt
|
||||
import scipy.ndimage as ndi
|
||||
import skimage.filters
|
||||
import numpy as np
|
||||
import scipy.ndimage as spnd
|
||||
from scipy.optimize import curve_fit
|
||||
import cv2
|
||||
|
||||
def image_center_of_mass(image=None, binarize=True,
|
||||
apply_threshold=True, threshold=None, median_filter=True,
|
||||
@@ -82,4 +86,41 @@ def image_center_of_mass(image=None, binarize=True,
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
return com_x, com_y
|
||||
return com_x, com_y
|
||||
def gaussian_2d(coords, amplitude, x0, y0, sigma_x, sigma_y, offset):
|
||||
x, y = coords
|
||||
return amplitude * np.exp(
|
||||
-(((x - x0) ** 2) / (2 * sigma_x ** 2) + ((y - y0) ** 2) / (2 * sigma_y ** 2))
|
||||
) + offset
|
||||
|
||||
def __process_img(img , retimg=0):
|
||||
z = np.float32(img)
|
||||
|
||||
z = spnd.zoom(z, 4, order=3)
|
||||
|
||||
z = cv2.GaussianBlur(z,(11,11),4)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Create a test image (e.g., 2D Gaussian)
|
||||
x = np.linspace(0, z.shape[0], z.shape[0])
|
||||
y = np.linspace(0, z.shape[1], z.shape[1])
|
||||
x, y = np.meshgrid(x, y)
|
||||
|
||||
|
||||
|
||||
# Flatten and fit
|
||||
x_gues, y_gues = image_center_of_mass(z, plot=False, verbose=False)
|
||||
max_a = np.max(z)-2
|
||||
|
||||
initial_guess = (max_a, x_gues, y_gues, 10, 10, 0)
|
||||
popt, _ = curve_fit(gaussian_2d, (x.ravel(), y.ravel()), z.ravel(), p0=initial_guess,maxfev=10000)
|
||||
|
||||
|
||||
x = popt[1]
|
||||
y = popt[2]
|
||||
if retimg:
|
||||
return x,y,z
|
||||
return x, y
|
||||
@@ -5,13 +5,14 @@ import matplotlib.pyplot as plt
|
||||
from pathlib import Path
|
||||
import queue
|
||||
import sys
|
||||
import scipy.ndimage as spnd
|
||||
import json
|
||||
import threading as th
|
||||
from scipy.optimize import curve_fit
|
||||
from PIL import Image, ImageDraw
|
||||
import numpy as np
|
||||
from utils import get_datestr, get_timestr
|
||||
|
||||
config_path = r"C:\Users\berti_r\Python_Projects\StagePerformaceDocu\Config\config.json" #Path to the config file which has the parameters for the next measurement
|
||||
library_path = r"C:\Users\berti_r\Python_Projects\templates\motion_libs" #Path to the motion function lib (ESS based)
|
||||
#library_path = r"C:\Users\berti_r\Python_Projects\templates\motion_libs" #Path to the motion function lib (ESS based)
|
||||
measurement_mov_path = r"C:\Users\berti_r\Python_Projects\StagePerformaceDocu\Config\measurement.json"
|
||||
workdir = \
|
||||
os.path.expanduser(rf'C:\Users\berti_r\Python_Projects\StagePerformaceDocu\data\data{get_datestr()}_alignment_tests')
|
||||
@@ -27,20 +28,16 @@ def check_path(path_str):
|
||||
print(f"Error: {e}")
|
||||
|
||||
check_path(config_path)
|
||||
check_path(library_path)
|
||||
sys.path.append(library_path)
|
||||
#check_path(library_path)
|
||||
#sys.path.append(library_path)
|
||||
check_path(measurement_mov_path)
|
||||
|
||||
import motionFunctionsLib as mfl # ToDo: comment out when using torque test
|
||||
from PIL import Image, ImageDraw
|
||||
import numpy as np
|
||||
from image_analysis import image_center_of_mass
|
||||
|
||||
from image_analysis import image_center_of_mass, __process_img
|
||||
import ad
|
||||
import myutility as myu
|
||||
import cv2
|
||||
import json
|
||||
import shutil
|
||||
|
||||
|
||||
|
||||
|
||||
if not os.path.exists(workdir):
|
||||
@@ -49,7 +46,7 @@ if not os.path.exists(workdir):
|
||||
# connect to PLC using NetId and PLC Port (from AIK in the TwinCat) TODO: <- comment out plc connect when using torque test
|
||||
plc = mfl.plc('5.67.222.118.1.1', 852)
|
||||
#TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
plc.connect()
|
||||
#plc.connect()
|
||||
axis2 = mfl.axis(plc, 2)
|
||||
|
||||
#insert try catch later
|
||||
@@ -78,11 +75,7 @@ def safe_meas_settings(save_path):
|
||||
print(f"dir: {save_path}")
|
||||
print(f"Error: {e}")
|
||||
|
||||
def gaussian_2d(coords, amplitude, x0, y0, sigma_x, sigma_y, offset):
|
||||
x, y = coords
|
||||
return amplitude * np.exp(
|
||||
-(((x - x0) ** 2) / (2 * sigma_x ** 2) + ((y - y0) ** 2) / (2 * sigma_y ** 2))
|
||||
) + offset
|
||||
|
||||
def compute_gradient(img, pos):
|
||||
x, y = pos
|
||||
x_int, y_int = int(x), int(y)
|
||||
@@ -145,37 +138,7 @@ def band_pass_filter(img_float, low_radius, high_radius):
|
||||
|
||||
return img_back
|
||||
|
||||
def __process_img(img , retimg=0):
|
||||
z = np.float32(img)
|
||||
|
||||
z = spnd.zoom(z, 4, order=3)
|
||||
|
||||
z = cv2.GaussianBlur(z,(11,11),4)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Create a test image (e.g., 2D Gaussian)
|
||||
x = np.linspace(0, z.shape[0], z.shape[0])
|
||||
y = np.linspace(0, z.shape[1], z.shape[1])
|
||||
x, y = np.meshgrid(x, y)
|
||||
|
||||
|
||||
|
||||
# Flatten and fit
|
||||
x_gues, y_gues = image_center_of_mass(z, plot=False, verbose=False)
|
||||
max_a = np.max(z)-2
|
||||
|
||||
initial_guess = (max_a, x_gues, y_gues, 10, 10, 0)
|
||||
popt, _ = curve_fit(gaussian_2d, (x.ravel(), y.ravel()), z.ravel(), p0=initial_guess,maxfev=10000)
|
||||
|
||||
|
||||
x = popt[1]
|
||||
y = popt[2]
|
||||
if retimg:
|
||||
return x,y,z
|
||||
return x, y
|
||||
|
||||
def aquire_avg(camera_a, nr=10):
|
||||
x_array = []
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user