Implement pixel counts.
This commit is contained in:
parent
dd7c1e8396
commit
236312f4a6
@ -78,7 +78,14 @@ public:
|
|||||||
sAppName = "Example";
|
sAppName = "Example";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Mode{
|
||||||
|
SongSelect,
|
||||||
|
Playing,
|
||||||
|
ScoreScreen
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Mode mode=SongSelect;
|
||||||
cv::Mat edges;
|
cv::Mat edges;
|
||||||
float frameView=0;
|
float frameView=0;
|
||||||
cv::VideoCapture video; // open the video file
|
cv::VideoCapture video; // open the video file
|
||||||
@ -115,27 +122,107 @@ public:
|
|||||||
FillRectDecal(pos+vf2d{0,size.y/2},size/2,{255,255,0,64});
|
FillRectDecal(pos+vf2d{0,size.y/2},size/2,{255,255,0,64});
|
||||||
FillRectDecal(pos+size/2,size/2,{0,255,0,64});
|
FillRectDecal(pos+size/2,size/2,{0,255,0,64});
|
||||||
vf2d fontSize={2,2};
|
vf2d fontSize={2,2};
|
||||||
|
DrawStringDecal(pos+vf2d{2,2},std::to_string(upperLeftPixelCount)+"/"+std::to_string(upperLeftDensity),BLACK,fontSize);
|
||||||
DrawStringDecal(pos+vf2d{1,1},std::to_string(upperLeftPixelCount)+"/"+std::to_string(upperLeftDensity),WHITE,fontSize);
|
DrawStringDecal(pos+vf2d{1,1},std::to_string(upperLeftPixelCount)+"/"+std::to_string(upperLeftDensity),WHITE,fontSize);
|
||||||
|
DrawStringDecal(pos+vf2d{size.x/2+2,2},std::to_string(upperRightPixelCount)+"/"+std::to_string(upperRightDensity),BLACK,fontSize);
|
||||||
DrawStringDecal(pos+vf2d{size.x/2+1,1},std::to_string(upperRightPixelCount)+"/"+std::to_string(upperRightDensity),WHITE,fontSize);
|
DrawStringDecal(pos+vf2d{size.x/2+1,1},std::to_string(upperRightPixelCount)+"/"+std::to_string(upperRightDensity),WHITE,fontSize);
|
||||||
|
DrawStringDecal(pos+vf2d{2,size.y/2+2},std::to_string(lowerLeftPixelCount)+"/"+std::to_string(lowerLeftDensity),BLACK,fontSize);
|
||||||
DrawStringDecal(pos+vf2d{1,size.y/2+1},std::to_string(lowerLeftPixelCount)+"/"+std::to_string(lowerLeftDensity),WHITE,fontSize);
|
DrawStringDecal(pos+vf2d{1,size.y/2+1},std::to_string(lowerLeftPixelCount)+"/"+std::to_string(lowerLeftDensity),WHITE,fontSize);
|
||||||
|
DrawStringDecal(pos+size/2+vf2d{2,2},std::to_string(lowerRightPixelCount)+"/"+std::to_string(lowerRightDensity),BLACK,fontSize);
|
||||||
DrawStringDecal(pos+size/2+vf2d{1,1},std::to_string(lowerRightPixelCount)+"/"+std::to_string(lowerRightDensity),WHITE,fontSize);
|
DrawStringDecal(pos+size/2+vf2d{1,1},std::to_string(lowerRightPixelCount)+"/"+std::to_string(lowerRightDensity),WHITE,fontSize);
|
||||||
std::string leftDisplayStr=std::to_string(leftPixelCount)+"/"+std::to_string(leftDensity);
|
std::string leftDisplayStr=std::to_string(leftPixelCount)+"/"+std::to_string(leftDensity);
|
||||||
|
DrawStringDecal(pos+vf2d{2+size.x/4,2+size.y+16}-GetTextSize(leftDisplayStr)*fontSize/2,leftDisplayStr,BLACK,fontSize);
|
||||||
DrawStringDecal(pos+vf2d{1+size.x/4,1+size.y+16}-GetTextSize(leftDisplayStr)*fontSize/2,leftDisplayStr,WHITE,fontSize);
|
DrawStringDecal(pos+vf2d{1+size.x/4,1+size.y+16}-GetTextSize(leftDisplayStr)*fontSize/2,leftDisplayStr,WHITE,fontSize);
|
||||||
std::string rightDisplayStr=std::to_string(rightPixelCount)+"/"+std::to_string(rightDensity);
|
std::string rightDisplayStr=std::to_string(rightPixelCount)+"/"+std::to_string(rightDensity);
|
||||||
|
DrawStringDecal(pos+vf2d{2+size.x*0.75f,2+size.y+16}-GetTextSize(rightDisplayStr)*fontSize/2,rightDisplayStr,BLACK,fontSize);
|
||||||
DrawStringDecal(pos+vf2d{1+size.x*0.75f,1+size.y+16}-GetTextSize(rightDisplayStr)*fontSize/2,rightDisplayStr,WHITE,fontSize);
|
DrawStringDecal(pos+vf2d{1+size.x*0.75f,1+size.y+16}-GetTextSize(rightDisplayStr)*fontSize/2,rightDisplayStr,WHITE,fontSize);
|
||||||
std::string centerDisplayStr=std::to_string(overallPixelCount)+"/"+std::to_string(overallDensity);
|
std::string centerDisplayStr=std::to_string(overallPixelCount)+"/"+std::to_string(overallDensity);
|
||||||
|
DrawStringDecal(pos+vf2d{2+size.x/2,2+size.y+48}-GetTextSize(centerDisplayStr)*fontSize/2,centerDisplayStr,BLACK,fontSize);
|
||||||
DrawStringDecal(pos+vf2d{1+size.x/2,1+size.y+48}-GetTextSize(centerDisplayStr)*fontSize/2,centerDisplayStr,WHITE,fontSize);
|
DrawStringDecal(pos+vf2d{1+size.x/2,1+size.y+48}-GetTextSize(centerDisplayStr)*fontSize/2,centerDisplayStr,WHITE,fontSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InLeftHalf(int x,int y){
|
||||||
|
vf2d pos=upperLeft;
|
||||||
|
vf2d size=lowerRight-upperLeft;
|
||||||
|
return x<pos.x+size.x/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InRightHalf(int x,int y){
|
||||||
|
vf2d pos=upperLeft;
|
||||||
|
vf2d size=lowerRight-upperLeft;
|
||||||
|
return x>=pos.x+size.x/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InTopHalf(int x,int y){
|
||||||
|
vf2d pos=upperLeft;
|
||||||
|
vf2d size=lowerRight-upperLeft;
|
||||||
|
return y<pos.y+size.y/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CalculatePixelCounts(int x,int y){
|
||||||
|
uint8_t col=edges.at<uint8_t>(y,x);
|
||||||
|
if(!col)return;
|
||||||
|
if(x<upperLeft.x||x>lowerRight.x||y<upperLeft.y||y>lowerRight.y)return;
|
||||||
|
overallPixelCount++;
|
||||||
|
int neighborAmt=(x>0&&edges.at<uint8_t>(y,x-1))+(x<edges.cols-1&&edges.at<uint8_t>(y,x+1))+(y>0&&edges.at<uint8_t>(y-1,x))+(y<edges.rows-1&&edges.at<uint8_t>(y+1,x));
|
||||||
|
overallDensity+=neighborAmt;
|
||||||
|
|
||||||
|
if(InLeftHalf(x,y)){
|
||||||
|
leftPixelCount++;
|
||||||
|
leftDensity+=neighborAmt;
|
||||||
|
if(InTopHalf(x,y)){
|
||||||
|
upperLeftPixelCount++;
|
||||||
|
upperLeftDensity+=neighborAmt;
|
||||||
|
}else{
|
||||||
|
lowerLeftPixelCount++;
|
||||||
|
lowerLeftDensity+=neighborAmt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(InRightHalf(x,y)){
|
||||||
|
rightPixelCount++;
|
||||||
|
rightDensity+=neighborAmt;
|
||||||
|
if(InTopHalf(x,y)){
|
||||||
|
upperRightPixelCount++;
|
||||||
|
upperRightDensity+=neighborAmt;
|
||||||
|
}else{
|
||||||
|
lowerRightPixelCount++;
|
||||||
|
lowerRightDensity+=neighborAmt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateCounts(){
|
||||||
|
if(!edgeDetect)return;
|
||||||
|
overallDensity=overallPixelCount=leftDensity=leftPixelCount=rightDensity=
|
||||||
|
rightPixelCount=lowerLeftDensity=lowerLeftPixelCount=upperLeftDensity=
|
||||||
|
upperLeftPixelCount=lowerRightDensity=lowerRightPixelCount=upperRightDensity=
|
||||||
|
upperRightPixelCount=0;
|
||||||
|
for(int y=0;y<edges.rows;y++){
|
||||||
|
for(int x=0;x<edges.cols;x++){
|
||||||
|
uint8_t col=edges.at<uint8_t>(y,x);
|
||||||
|
if(col){
|
||||||
|
CalculatePixelCounts(x,y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void UpdateScreen(){
|
void UpdateScreen(){
|
||||||
Clear(BLACK);
|
Clear(BLACK);
|
||||||
|
overallDensity=overallPixelCount=leftDensity=leftPixelCount=rightDensity=
|
||||||
|
rightPixelCount=lowerLeftDensity=lowerLeftPixelCount=upperLeftDensity=
|
||||||
|
upperLeftPixelCount=lowerRightDensity=lowerRightPixelCount=upperRightDensity=
|
||||||
|
upperRightPixelCount=0;
|
||||||
cv::Mat targetFrame=get_frame(video,std::clamp(int(frameView),0,int(video.get(cv::CAP_PROP_FRAME_COUNT))));
|
cv::Mat targetFrame=get_frame(video,std::clamp(int(frameView),0,int(video.get(cv::CAP_PROP_FRAME_COUNT))));
|
||||||
if(edgeDetect){
|
if(edgeDetect){
|
||||||
cv::Canny(targetFrame,edges,edgeLowerThreshold,edgeUpperThreshold);
|
cv::Canny(targetFrame,edges,edgeLowerThreshold,edgeUpperThreshold);
|
||||||
for(int y=0;y<edges.rows;y++){
|
for(int y=0;y<edges.rows;y++){
|
||||||
for(int x=0;x<edges.cols;x++){
|
for(int x=0;x<edges.cols;x++){
|
||||||
uint8_t col=edges.at<uint8_t>(y,x);
|
uint8_t col=edges.at<uint8_t>(y,x);
|
||||||
Draw(x,y,{col,col,col});
|
if(col){
|
||||||
|
//Draw(x,y,{col,col,col});
|
||||||
|
CalculatePixelCounts(x,y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@ -159,7 +246,7 @@ public:
|
|||||||
UpdateScreen();
|
UpdateScreen();
|
||||||
}
|
}
|
||||||
if(GetKey(RIGHT).bHeld){
|
if(GetKey(RIGHT).bHeld){
|
||||||
frameView+=fElapsedTime*60;
|
frameView+=1;
|
||||||
UpdateScreen();
|
UpdateScreen();
|
||||||
}
|
}
|
||||||
if(GetKey(LEFT).bPressed){
|
if(GetKey(LEFT).bPressed){
|
||||||
@ -167,7 +254,7 @@ public:
|
|||||||
UpdateScreen();
|
UpdateScreen();
|
||||||
}
|
}
|
||||||
if(GetKey(LEFT).bHeld){
|
if(GetKey(LEFT).bHeld){
|
||||||
frameView-=fElapsedTime*60;
|
frameView-=1;
|
||||||
UpdateScreen();
|
UpdateScreen();
|
||||||
}
|
}
|
||||||
if(!cabDetected){
|
if(!cabDetected){
|
||||||
@ -184,9 +271,11 @@ public:
|
|||||||
}
|
}
|
||||||
if(GetMouse(Mouse::LEFT).bHeld){
|
if(GetMouse(Mouse::LEFT).bHeld){
|
||||||
lowerRight=GetMousePos();
|
lowerRight=GetMousePos();
|
||||||
|
UpdateCounts();
|
||||||
}
|
}
|
||||||
if(GetMouse(Mouse::LEFT).bReleased){
|
if(GetMouse(Mouse::LEFT).bReleased){
|
||||||
dragging=false;
|
dragging=false;
|
||||||
|
UpdateCounts();
|
||||||
}
|
}
|
||||||
if(GetKey(HOME).bPressed){
|
if(GetKey(HOME).bPressed){
|
||||||
edgeDetect=!edgeDetect;
|
edgeDetect=!edgeDetect;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user