Skip to content

Commit

Permalink
Merge pull request #1 from Neutralizer/bgUpdateRate
Browse files Browse the repository at this point in the history
Background update rate slider added
  • Loading branch information
Neutralizer authored Jun 3, 2020
2 parents 38a514e + 2294d2a commit ce1dfec
Show file tree
Hide file tree
Showing 28 changed files with 54 additions and 29 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
### 0.1.2 -
* Planned improvements section added
### 0.1.2 - 03.06.2020
* Added background learning rate slider (reducing the autofocus flicker problem)
* Restructured slider UI

### 0.1.1 - 17.10.2019
* Better resource release
* Disabled javacv logging
* Flicker limiter added
* fixed personal error logging
* added custom W rectangle button to automatically created preset
* Planned improvements section added

### 0.1.0 - 07.04.2019
* Minor optimization of main cycle
Expand Down Expand Up @@ -54,6 +56,6 @@
* Shown resolution and fps counter in frame header

### 0.0.1 - 10.11.2018
* Initial Alpha version
* Initial Pre-Alpha version


Empty file added ErrorLog.log
Empty file.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Introduction
This program is designed with the idea of losing weight while playing computer games <b>on a budget</b>. It is based on 2 technologies - computer vision and game bot command issuing(automation testing): Movement is detected in specific regions via a web camera (or emulated smartphone camera) and when it is detected, the respective keyboard key attached to that region is being pressed.
## Disclaimer
The movement controller is in its BETA state now, but is still unfinished. Check Known Issues section if you encounter any problems.
The movement controller is in its Alpha state now and is still unfinished. Check Known Issues section if you encounter any problems.
## Getting Started
What should I do to run the program:
### Download
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class MovementDetector implements Detector {
int subractorThreshold = 10;// 16
int detectionLimitPercentage = 75;
int totalMovementFoundPercentage = 0;
int backgroundUpdateRate = 5;//0-100

public MovementDetector() {
this.firstKernelErode = opencv_imgproc.getStructuringElement(opencv_imgproc.MORPH_RECT,
Expand Down Expand Up @@ -89,14 +90,20 @@ public void changeDetectionLimit(int detLimit) {
}
}

public void changebackgroundUpdateRate(int bgUpdateRate) {
if (backgroundUpdateRate != bgUpdateRate) {
backgroundUpdateRate = bgUpdateRate;
}
}

public int getTotalMovementPercentage() {
return totalMovementFoundPercentage;
}

public void processImage(IplImage img, Mat bgResult) {
Mat imgMat = new Mat(img);

fgbg.apply(imgMat, bgResult);
fgbg.apply(imgMat, bgResult, backgroundUpdateRate / 100d);

opencv_imgproc.medianBlur(bgResult, bgResult, blurSize);

Expand Down
29 changes: 14 additions & 15 deletions src/main/java/interfacePanel/panel/KeyTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,15 @@ public void mouseClicked(MouseEvent e) {
});
}

/**
* Generate and populate table with virtual buttons
* @param c GridBagConstraints for align
* @param frame The panel onto which the table will be displayed
*/
public void createTable(GridBagConstraints c, JPanel frame) {
int startPosY = 16;
c.gridx = 0;
c.gridy = 14;
c.gridy = startPosY;
table = new JTable();
table.setPreferredScrollableViewportSize(new Dimension(400, 100));
table.setFillsViewportHeight(true);
Expand Down Expand Up @@ -171,34 +177,27 @@ public boolean isCellEditable(int row, int column) {

frame.add(pane, c);

c.gridx = 0;
c.gridy = 15;
c.gridy = startPosY++;
frame.add(comboBoxKeyName, c);

c.gridx = 0;
c.gridy = 16;
c.gridy = startPosY++;
frame.add(locText, c);

c.gridx = 0;
c.gridy = 17;
c.gridy = startPosY++;
frame.add(comboBoxKeyType, c);

// add JButtons to the jframe

c.gridx = 0;
c.gridy = 18;
c.gridy = startPosY++;
frame.add(btnAdd, c);

c.gridx = 0;
c.gridy = 19;
c.gridy = startPosY++;
frame.add(btnDelete, c);

c.gridx = 0;
c.gridy = 20;
c.gridy = startPosY++;
frame.add(btnUpdate, c);

c.gridx = 0;
c.gridy = 21;
c.gridy = startPosY++;
frame.add(btnSave, c);

row = new Object[3];
Expand Down
33 changes: 25 additions & 8 deletions src/main/java/interfacePanel/panel/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,27 @@ public class MainPanel extends JFrame {
private JButton buttonCameraProperties = new JButton("UNSTABLE:Camera Properties");

String buttonCameraPropertiesHover = "Opens current camera properties. It is advised "
+ "after accessing the properties to start the camera, or it may become locked";
String buttonCameraHover = "Starts the camera and the controller";
String boxCameraHover = "Shows available cameras";
String boxPropertiesHover = "Shows available presets as .properties files in current folder";
+ "after accessing the properties to start the camera, or it may become locked.";
String buttonCameraHover = "Starts the camera and the controller.";
String boxCameraHover = "Shows available cameras.";
String boxPropertiesHover = "Shows available presets as .properties files in current folder.";
String erodeHover = "Remove noise from camera input. More means less noise.";
String dilateHover = "Makes found pixels bigger";
String dilateHover = "Makes found pixels bigger.";
String historyHover = "Creates trail from detected pixels. Also removes noise.";
String threshHover = "Controls main detection. More means less detection";
String blurHover = "Blurs the image to reduce noise";
String threshHover = "Controls main detection. More means less detection.";
String blurHover = "Blurs the image to reduce noise.";
String limiterHover = "When there is too much detection on the screen the buttons will not be pressed. "
+ "At 50 - when there is more than 50% white on the screen the buttons will not be pressed."
+ "To disable the limiter set it to 100%";
+ "To disable the limiter set it to 100%. To disable detection set it to 0%.";
String backgroundUpdateRateHover = "Reduces flickering. Less is better controlled detection.";

JSlider sliderBlur = new JSlider(1, 19, 5);
JSlider sliderErode1 = new JSlider(1, 15, 3);
JSlider sliderDilate2 = new JSlider(1, 15, 3);
JSlider sliderHistory = new JSlider(1, 50, 4);
JSlider sliderThresh = new JSlider(1, 100, 10);
JSlider sliderLimiter = new JSlider(50, 100, 75);
JSlider sliderBgUpdateRate = new JSlider(0, 100, 5);

GridBagConstraints c;
JPanel panelMain;
Expand Down Expand Up @@ -166,8 +168,11 @@ public void actionPerformed(ActionEvent e) {
sliderTemplate(panelForm, c, sliderErode1, "Erode", erodeHover, 2, 1);
sliderTemplate(panelForm, c, sliderDilate2, "Dilate", dilateHover, 2, 1);
sliderTemplate(panelForm, c, sliderHistory, "History", historyHover, 10, 1);
c.gridx = 1;// 2nd col
c.gridy = 2;
sliderTemplate(panelForm, c, sliderThresh, "Threshold", threshHover, 10, 1);
sliderTemplate(panelForm, c, sliderLimiter, "Limiter", limiterHover, 10, 5);
sliderTemplate(panelForm, c, sliderBgUpdateRate, "Background Update Rate", backgroundUpdateRateHover, 10, 1);

sliderBlur.addChangeListener(new ChangeListener() {

Expand Down Expand Up @@ -244,6 +249,18 @@ public void stateChanged(ChangeEvent e) {
}
}
});

sliderBgUpdateRate.addChangeListener(new ChangeListener() {

@Override
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider) e.getSource();
if (!source.getValueIsAdjusting()) {
int value = (int) source.getValue();
detector.changebackgroundUpdateRate(value);
}
}
});

// 2nd column
c.anchor = GridBagConstraints.LINE_START;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Tue Oct 15 23:52:26 EEST 2019
#Tue Jun 02 23:11:20 EEST 2020
version=0.0.1-SNAPSHOT
groupId=cv
m2e.projectName=MovementControllerByNeutralizer
Expand Down
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/KeyTable$2.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/KeyTable$3.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/KeyTable$4.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/KeyTable$5.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/KeyTable$6.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/KeyTable$7.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/KeyTable.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/MainPanel$1.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/MainPanel$10.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/MainPanel$11.class
Binary file not shown.
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/MainPanel$2.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/MainPanel$3.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/MainPanel$4.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/MainPanel$5.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/MainPanel$6.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/MainPanel$7.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/MainPanel$8.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/MainPanel$9.class
Binary file not shown.
Binary file modified target/classes/interfacePanel/panel/MainPanel.class
Binary file not shown.

0 comments on commit ce1dfec

Please sign in to comment.