Skip to content

Commit

Permalink
Merge pull request #3 from Neutralizer/add-pause-button
Browse files Browse the repository at this point in the history
Added pause toggle button that halts virtual button execution
  • Loading branch information
Neutralizer committed May 18, 2021
2 parents e67b820 + cb15ac3 commit a5556c0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 0.1.3 - 18.05.2021
* Added pause button to halt virtual button execution
* Added pause textual indication on camera panel header (when paused)

### 0.1.2 - 03.06.2020
* Added background learning rate slider (reducing the autofocus flicker problem)
* Restructured slider UI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class MovementDetector implements Detector {
int detectionLimitPercentage = 75;
int totalMovementFoundPercentage = 0;
int backgroundUpdateRate = 5;//0-100
public boolean isPaused = false;

public MovementDetector() {
this.firstKernelErode = opencv_imgproc.getStructuringElement(opencv_imgproc.MORPH_RECT,
Expand Down Expand Up @@ -99,6 +100,14 @@ public void changebackgroundUpdateRate(int bgUpdateRate) {
public int getTotalMovementPercentage() {
return totalMovementFoundPercentage;
}

public boolean getIsPaused() {
return isPaused;
}

public void setIsPaused(boolean isPaused) {
this.isPaused = isPaused;
}

public void processImage(IplImage img, Mat bgResult) {
Mat imgMat = new Mat(img);
Expand All @@ -120,6 +129,14 @@ public String tellIfMovementDetectionIsBlocked() {
}
}

public String tellIfPaused() {
if(isPaused) {
return "PAUSED";
} else {
return "";
}
}

/**
*
* If too much movement is detected on the whole screen, then it is a flicker and do not press buttons.
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/bgSubtraction/main/MainMovement.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,16 @@ public void run() {
roi.getListRoi().get(roi.getListRoi().size()-1).getKey().setKeyCode(keyWS);
}

if(!movementDetector.isMovementDetectedAndLimitReached(bgResult)) {
if(!movementDetector.isMovementDetectedAndLimitReached(bgResult) && !movementDetector.isPaused) {
roi.executeAllROI(bgResult);
}


display.drawAllROI(roi.getListRoi(), bgResult);
display.showImage(bgResult);

display.setTitle("Resolution: " + camera.getCameraWidthAndHeight() + "; FPS: "
+ Integer.toString(camera.getFPS()) + "; Total Movement: " +
movementDetector.getTotalMovementPercentage() + "% " +
movementDetector.getTotalMovementPercentage() + "% " + " " + movementDetector.tellIfPaused() +
movementDetector.tellIfMovementDetectionIsBlocked());

// display.attachMouseListener();//TODO attaches mouse listener
Expand Down
31 changes: 29 additions & 2 deletions src/main/java/interfacePanel/panel/MainPanel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package interfacePanel.panel;

import java.awt.Color;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
Expand Down Expand Up @@ -324,8 +325,34 @@ private void sliderTemplate(JPanel panelForm, GridBagConstraints c, JSlider slid
private void startExecution() {
comboBoxCamera.setEnabled(false);
comboBoxPresets.setEnabled(false);
buttonStartCamera.setEnabled(false);
buttonCameraProperties.setEnabled(false);
buttonStartCamera.setVisible(false);
buttonCameraProperties.setVisible(false);

//-- Pause button
c.gridx = 1;// 2nd col
c.gridy = 0;
final JButton buttonTogglePause = new JButton("Pause");
buttonTogglePause.setBackground(Color.GREEN);

buttonTogglePause.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
//if it is not paused, pause it; else unpause it
if(!detector.getIsPaused()) {
detector.setIsPaused(true);
buttonTogglePause.setBackground(Color.RED);
buttonTogglePause.setText("Paused");
} else {
detector.setIsPaused(false);
buttonTogglePause.setBackground(Color.GREEN);
buttonTogglePause.setText("Pause");
}

}
});
panelForm.add(buttonTogglePause,c);
//--

int cameraNum = util.getCameraNum(cameras, comboBoxCamera.getSelectedItem().toString());
String selectedPropFile = comboBoxPresets.getSelectedItem().toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Tue Jun 02 23:11:20 EEST 2020
#Mon May 17 23:10:06 EEST 2021
version=0.0.1-SNAPSHOT
groupId=cv
m2e.projectName=MovementControllerByNeutralizer
Expand Down

0 comments on commit a5556c0

Please sign in to comment.