-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplifying to a single file, perf improvements, better user experience #7
Open
JesseBuesking
wants to merge
9
commits into
leswright1977:main
Choose a base branch
from
JesseBuesking:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d45e46b
combine logic into a single fle
JesseBuesking 8ead4f0
updating readme
JesseBuesking 61dd6c1
more readme changes
JesseBuesking eca08d0
support for different frameWidth and frameHeight
JesseBuesking 7f5bd00
performance improvements
JesseBuesking ab47a5a
update the graticule when modified
JesseBuesking 25c3738
take the peak nearest to where the user clicked
JesseBuesking 005248d
fixing bugs in mouse clicks and graticule
JesseBuesking 7e21695
a bit of cleanup, and a few more perf improvements
JesseBuesking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ | |
import cv2 | ||
import time | ||
import numpy as np | ||
from specFunctions import wavelength_to_rgb,savitzky_golay,peakIndexes,readcal,writecal,background,generateGraticule | ||
from specFunctions import wavelength_to_rgb,savitzky_golay,peakIndexes,readcal,writecal,background,generateGraticule,closest | ||
import base64 | ||
import argparse | ||
from pprint import pprint | ||
|
@@ -60,7 +60,7 @@ | |
if args.device: | ||
dev = args.device | ||
|
||
|
||
peak_intensities = [] | ||
frameWidth = 800 | ||
frameHeight = 600 | ||
message_loc1 = frameWidth - 310 | ||
|
@@ -144,17 +144,40 @@ | |
cursorX = 0 | ||
cursorY = 0 | ||
def handle_mouse(event,x,y,flags,param): | ||
global clickArray | ||
global cursorX | ||
global cursorY | ||
global clickArray, cursorX, cursorY, peak_intensities, wavelengthData | ||
mouseYOffset = 160 | ||
if event == cv2.EVENT_MOUSEMOVE: | ||
cursorX = x | ||
cursorY = y | ||
if event == cv2.EVENT_LBUTTONDOWN: | ||
elif event == cv2.EVENT_LBUTTONDOWN: | ||
mouseX = x | ||
mouseY = y-mouseYOffset | ||
clickArray.append([mouseX,mouseY]) | ||
if len(peak_intensities) > 0: | ||
# use raw peaks | ||
closest_peak_index = 0 | ||
peak_distance = 5 | ||
left = mouseX - peak_distance | ||
right = mouseX + peak_distance | ||
peak_index = 0 | ||
peak_intensity = 0 | ||
for index, i in enumerate(raw_intensity[left:right]): | ||
if i > peak_intensity: | ||
peak_intensity = i | ||
peak_index = index+left | ||
closest_peak_index = peak_index | ||
|
||
# # use labeled peaks | ||
# closest_peak_index = closest(peak_intensities, mouseX) | ||
|
||
wl = wavelengthData[closest_peak_index] | ||
clickArray.append([mouseX, mouseY, closest_peak_index, wl]) | ||
print("added a point for peak {:.1f}nm at {}".format(wl, closest_peak)) | ||
elif event == cv2.EVENT_RBUTTONDOWN: | ||
if len(clickArray) == 0: | ||
return | ||
_, _, closest_peak, wl = clickArray[-1] | ||
print("removing point for peak {:.1f}nm at {}".format(wl, closest_peak)) | ||
clickArray = clickArray[:-1] | ||
#listen for click on plot window | ||
cv2.setMouseCallback(title1,handle_mouse) | ||
|
||
|
@@ -258,7 +281,7 @@ def snapshot(savedata): | |
cap.isOpened() | ||
|
||
def runall(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I turned this into a function so that I could more easily profile the logic. |
||
global graticuleData, tens, fifties, msg1, saveMsg, waterfall, wavelengthData | ||
global graticuleData, tens, fifties, msg1, saveMsg, waterfall, wavelengthData, peak_intensities | ||
global caldata, calmsg1, calmsg2, calmsg3, savpoly, mindist, thresh | ||
global calibrate, clickArray, cursorX, cursorY, picamGain, spectrum_vertical, waterfall_vertical | ||
global graph, graph_base, wavelength_data_rgbs, raw_intensity, picam2, cap | ||
|
@@ -353,9 +376,9 @@ def runall(): | |
#find peaks and label them | ||
textoffset = 12 | ||
thresh = int(thresh) #make sure the data is int. | ||
peak_indexes = peakIndexes(intensity, thres=thresh/max(intensity), min_dist=mindist) | ||
peak_intensities = peakIndexes(intensity, thres=thresh/max(intensity), min_dist=mindist) | ||
|
||
for i in peak_indexes: | ||
for i in peak_intensities: | ||
height = intensity[i] | ||
height = 310-height | ||
wavelength = round(wavelengthData[i],1) | ||
|
@@ -381,7 +404,7 @@ def runall(): | |
clickArray = [] | ||
|
||
if clickArray: | ||
for mouseX, mouseY in clickArray: | ||
for mouseX, mouseY, _, _ in clickArray: | ||
cv2.circle(graph,(mouseX,mouseY),5,(0,0,0),-1) | ||
#we can display text :-) so we can work out wavelength from x-pos and display it ultimately | ||
cv2.putText(graph,str(mouseX),(mouseX+5,mouseY),cv2.FONT_HERSHEY_SIMPLEX,0.4,(0,0,0)) | ||
|
@@ -456,9 +479,9 @@ def runall(): | |
keyPress = cv2.waitKey(1) | ||
if keyPress == -1: | ||
break | ||
elif keyPress == ord('q'): | ||
elif keyPress == ord("q"): | ||
return | ||
elif keyPress == ord('h'): | ||
elif keyPress == ord("h"): | ||
holdpeaks = not holdpeaks | ||
elif keyPress == ord("s"): | ||
#package up the data! | ||
|
@@ -476,7 +499,7 @@ def runall(): | |
savedata.append(graphdata) | ||
saveMsg = snapshot(savedata) | ||
elif keyPress == ord("c"): | ||
if writecal(clickArray): | ||
if writecal(clickArray, frameWidth): | ||
#overwrite wavelength data | ||
#Go grab the computed calibration data | ||
caldata = readcal(frameWidth) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if selecting a peak within +/- 5 pixels is better, or if choosing the closest label is. I've left +/-5 on, but maybe this could also be an option enabled by passable arguments?