|
1 |
| - |
2 |
| -from ximea import xiapi |
3 |
| -import cv2 |
4 |
| -import numpy as np |
5 |
| -import time |
6 |
| -import sys,os |
7 |
| -import pickle |
8 |
| -from termcolor import colored |
9 |
| -import config as config |
10 |
| - |
11 |
| -def work(frame): |
12 |
| - f = np.fft.fft2(frame) |
13 |
| - fshift = np.fft.fftshift(f) |
14 |
| - magnitude_spectrum = 20*np.log(np.abs(fshift)) |
15 |
| - magnitude_spectrum = np.asarray(magnitude_spectrum, dtype=np.uint8) |
16 |
| - return magnitude_spectrum |
17 |
| - |
18 |
| -if __name__ == '__main__': |
19 |
| - cam = xiapi.Camera() |
20 |
| - print('Opening first camera...') |
21 |
| - cam.open_device() |
22 |
| - cam.set_exposure(config.exposure) |
23 |
| - cam.set_param('width',config.resolution) |
24 |
| - cam.set_param('height',config.resolution) |
25 |
| - cam.set_param('downsampling_type', 'XI_SKIPPING') |
26 |
| - cam.set_acq_timing_mode('XI_ACQ_TIMING_MODE_FREE_RUN') |
27 |
| - |
28 |
| - img = xiapi.Image() |
29 |
| - print('Starting data acquisition...') |
30 |
| - cam.start_acquisition() |
31 |
| - |
32 |
| - while True : |
33 |
| - cam.get_image(img) |
34 |
| - frame = img.get_image_data_numpy() |
35 |
| - frame = cv2.flip(frame, 0) # flip the frame vertically |
36 |
| - frame = cv2.flip(frame, 1) |
37 |
| - cv2.imshow("Xemia Camera LIVE ",frame) |
38 |
| - fps.update() |
39 |
| - key = cv2.waitKey(1) & 0xFF |
40 |
| - # if the `q` key was pressed, break from the loop |
41 |
| - if key == ord('q'): |
42 |
| - break |
43 |
| - cv2.waitKey(2) |
44 |
| - cv2.destroyAllWindows() |
45 |
| - cam.get_image(img) |
46 |
| - frame = img.get_image_data_numpy() |
47 |
| - frame = cv2.flip(frame, 0) # flip the frame vertically |
48 |
| - frame = cv2.flip(frame, 1) |
49 |
| - roimain=cv2.selectROI("Main Bead select",frame) |
50 |
| - cv2.destroyAllWindows() |
51 |
| - roiref=cv2.selectROI("Reference Bead select",frame) |
52 |
| - cv2.destroyAllWindows() |
53 |
| - while True: |
54 |
| - cam.get_image(img) |
55 |
| - frame = img.get_image_data_numpy() |
56 |
| - frame = cv2.flip(frame, 0) # flip the frame vertically |
57 |
| - frame = cv2.flip(frame, 1) |
58 |
| - fft = work(frame[int(roimain[1]):int(roimain[1]+roimain[3]), int(roimain[0]):int(roimain[0]+roimain[2])]) |
59 |
| - fft = cv2.resize(fft, (256, 256),interpolation = cv2.INTER_NEAREST) |
60 |
| - cv2.imshow("FFT",fft) |
61 |
| - cv2.imshow("LIVE",frame) |
62 |
| - fps.update() |
63 |
| - key = cv2.waitKey(2) & 0xFF |
64 |
| - # if the `q` key was pressed, break from the loop |
65 |
| - if key == ord('q'): |
66 |
| - break |
67 |
| - cv2.waitKey(2) |
68 |
| - |
69 |
| - |
70 |
| - cam.stop_acquisition() |
71 |
| - cam.close_device() |
72 |
| - os._exit(1) |
73 |
| - # sys.exit() |
74 |
| - |
75 |
| - |
76 |
| - |
77 |
| - |
78 |
| - |
79 |
| - |
80 |
| - |
| 1 | + |
| 2 | +from ximea import xiapi |
| 3 | +import cv2 |
| 4 | +import numpy as np |
| 5 | +import time |
| 6 | +import sys,os |
| 7 | +import pickle |
| 8 | +from termcolor import colored |
| 9 | +import config as config |
| 10 | + |
| 11 | +def work(frame): |
| 12 | + f = np.fft.fft2(frame) |
| 13 | + fshift = np.fft.fftshift(f) |
| 14 | + magnitude_spectrum = 20*np.log(np.abs(fshift)) |
| 15 | + magnitude_spectrum = np.asarray(magnitude_spectrum, dtype=np.uint8) |
| 16 | + return magnitude_spectrum |
| 17 | + |
| 18 | +if __name__ == '__main__': |
| 19 | + cam = xiapi.Camera() |
| 20 | + print('Opening first camera...') |
| 21 | + cam.open_device() |
| 22 | + cam.set_exposure(config.exposure) |
| 23 | + cam.set_param('width',config.resolution) |
| 24 | + cam.set_param('height',config.resolution) |
| 25 | + cam.set_param('downsampling_type', 'XI_SKIPPING') |
| 26 | + cam.set_acq_timing_mode('XI_ACQ_TIMING_MODE_FREE_RUN') |
| 27 | + |
| 28 | + img = xiapi.Image() |
| 29 | + print('Starting data acquisition...') |
| 30 | + cam.start_acquisition() |
| 31 | + |
| 32 | + while True : |
| 33 | + cam.get_image(img) |
| 34 | + frame = img.get_image_data_numpy() |
| 35 | + frame = cv2.flip(frame, 0) # flip the frame vertically |
| 36 | + frame = cv2.flip(frame, 1) |
| 37 | + cv2.imshow("Xemia Camera LIVE ",frame) |
| 38 | + fps.update() |
| 39 | + key = cv2.waitKey(1) & 0xFF |
| 40 | + # if the `q` key was pressed, break from the loop |
| 41 | + if key == ord('q'): |
| 42 | + break |
| 43 | + cv2.waitKey(2) |
| 44 | + cv2.destroyAllWindows() |
| 45 | + cam.get_image(img) |
| 46 | + frame = img.get_image_data_numpy() |
| 47 | + frame = cv2.flip(frame, 0) # flip the frame vertically |
| 48 | + frame = cv2.flip(frame, 1) |
| 49 | + roimain=cv2.selectROI("Main Bead select",frame) |
| 50 | + cv2.destroyAllWindows() |
| 51 | + roiref=cv2.selectROI("Reference Bead select",frame) |
| 52 | + cv2.destroyAllWindows() |
| 53 | + while True: |
| 54 | + cam.get_image(img) |
| 55 | + frame = img.get_image_data_numpy() |
| 56 | + frame = cv2.flip(frame, 0) # flip the frame vertically |
| 57 | + frame = cv2.flip(frame, 1) |
| 58 | + fft = work(frame[int(roimain[1]):int(roimain[1]+roimain[3]), int(roimain[0]):int(roimain[0]+roimain[2])]) |
| 59 | + fft = cv2.resize(fft, (256, 256),interpolation = cv2.INTER_NEAREST) |
| 60 | + cv2.imshow("FFT",fft) |
| 61 | + cv2.imshow("LIVE",frame) |
| 62 | + fps.update() |
| 63 | + key = cv2.waitKey(2) & 0xFF |
| 64 | + # if the `q` key was pressed, break from the loop |
| 65 | + if key == ord('q'): |
| 66 | + break |
| 67 | + cv2.waitKey(2) |
| 68 | + |
| 69 | + |
| 70 | + cam.stop_acquisition() |
| 71 | + cam.close_device() |
| 72 | + os._exit(1) |
| 73 | + # sys.exit() |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
0 commit comments