You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.5 KiB
Java
77 lines
2.5 KiB
Java
void densityMeasure(int x, int y, int gameScreenWidth, int gameScreenHeight) {
|
|
switch (densitySession) {
|
|
case 0:
|
|
densityMeasureTotalScreen();
|
|
break;
|
|
case 1:
|
|
densityMeasureROI(x, y, gameScreenWidth, gameScreenHeight);
|
|
break;
|
|
case 2:
|
|
calculatePercentDensity();
|
|
break;
|
|
default :
|
|
startSession = 5;
|
|
break;
|
|
}
|
|
}
|
|
|
|
void densityMeasureTotalScreen() {
|
|
// text("Whole Screen", 300, 600);
|
|
if (millis() - densityTSTime <= 2000) {
|
|
entireScreen = get(0, 0, screenWidth, screenHeight); // Get pixels of interest and saves as image for valid image path
|
|
opencv5.loadImage(entireScreen); // Input proper pixels into cv processing
|
|
opencv5.updateBackground(); //Necessary for background subtraction
|
|
opencv5.useGray(); //Create grayscale image
|
|
opencv5.dilate(); //Clean up image
|
|
opencv5.erode();
|
|
opencv5.blur(3);
|
|
cvscreen = opencv5.getOutput(); //Save computer vision as separate image path
|
|
euglenaCount = opencv5.findContours(); //Find outline of moving objects - euglena
|
|
totalCount = euglenaCount.size();
|
|
} else {
|
|
densityROITime = millis();
|
|
densitySession = 1;
|
|
}
|
|
}
|
|
|
|
void densityMeasureROI(int x, int y, int gameScreenWidth, int gameScreenHeight) {
|
|
// text("Region of Interest", 300, 600);
|
|
if (millis() - densityROITime <= 2000) {
|
|
gameScreen = get(x, y, gameScreenWidth, gameScreenHeight); // Get pixels of interest and saves as image for valid image path
|
|
opencv4.loadImage(gameScreen); // Input proper pixels into cv processing
|
|
opencv4.updateBackground(); //Necessary for background subtraction
|
|
opencv4.useGray(); //Create grayscale image
|
|
opencv4.dilate(); //Clean up image
|
|
opencv4.erode();
|
|
opencv4.blur(3);
|
|
o3 = opencv4.getOutput(); //Save computer vision as separate image path
|
|
//image(o3, x - gameScreenWidth, y);
|
|
contours = opencv4.findContours(); //Find outline of moving objects - euglena
|
|
count = contours.size();
|
|
} else {
|
|
displayDensityTime = millis();
|
|
densitySession = 2;
|
|
}
|
|
}
|
|
|
|
void calculatePercentDensity() {
|
|
// if (millis() - displayDensityTime <= 4000) {
|
|
// text(count + " " + totalCount, 600, 900);
|
|
// delay(1000);
|
|
percentDensity = ((float)count/ (float)totalCount)*100;
|
|
densityMeasured = true;
|
|
// } else {
|
|
// densityTSTime = millis();
|
|
densitySession = 0;
|
|
// }
|
|
|
|
}
|
|
|
|
void displayDensity() {
|
|
if(percentDensity != 0) {
|
|
textSize(56);
|
|
fill(color(180, 0, 0));
|
|
text("% Density: " + percentDensity, 100, 100);
|
|
}
|
|
}
|