@ -79,9 +79,12 @@ public:
}
public :
std : : vector < cv : : Mat > fram es;
cv : : Mat edg es ;
float frameView = 0 ;
cv : : VideoCapture video ; // open the video file
bool edgeDetect = true ;
float edgeLowerThreshold = 150 ;
float edgeUpperThreshold = 255 ;
bool OnUserCreate ( ) override
{
// Called once at the start, so create things here
@ -92,10 +95,20 @@ public:
void UpdateScreen ( ) {
Clear ( BLACK ) ;
cv : : Mat targetFrame = get_frame ( video , std : : clamp ( int ( frameView ) , 0 , int ( video . get ( cv : : CAP_PROP_FRAME_COUNT ) ) ) ) ;
for ( int y = 0 ; y < targetFrame . rows ; y + + ) {
for ( int x = 0 ; x < targetFrame . cols ; x + + ) {
cv : : Vec3b col = targetFrame . at < cv : : Vec3b > ( y , x ) ;
Draw ( x , y , { col [ 2 ] , col [ 1 ] , col [ 0 ] } ) ;
if ( edgeDetect ) {
cv : : Canny ( targetFrame , edges , edgeLowerThreshold , edgeUpperThreshold ) ;
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 ) ;
Draw ( x , y , { col , col , col } ) ;
}
}
} else {
for ( int y = 0 ; y < targetFrame . rows ; y + + ) {
for ( int x = 0 ; x < targetFrame . cols ; x + + ) {
cv : : Vec3b col = targetFrame . at < cv : : Vec3b > ( y , x ) ;
Draw ( x , y , { col [ 2 ] , col [ 1 ] , col [ 0 ] } ) ;
}
}
}
}
@ -124,8 +137,9 @@ public:
}
if ( ! cabDetected ) {
DrawString ( { 4 , ScreenHeight ( ) - 40 } , " Drag over the region where the cab's screen is located. \n (Make sure the entire cabinet screen is covered) " , WHITE , 2 ) ;
SetPixelMode ( Pixel : : ALPHA ) ;
FillRectDecal ( upperLeft , lowerRight - upperLeft , { 255 , 255 , 255 , 128 } ) ;
DrawString ( { 4 , ScreenHeight ( ) - 40 - 16 } , " Upper Threshold: " + std : : to_string ( edgeUpperThreshold ) , WHITE , 2 ) ;
DrawString ( { 4 , ScreenHeight ( ) - 40 - 32 } , " Lower Threshold: " + std : : to_string ( edgeLowerThreshold ) , WHITE , 2 ) ;
}
if ( GetMouse ( Mouse : : LEFT ) . bPressed ) {
if ( ! dragging ) {
@ -139,6 +153,21 @@ public:
if ( GetMouse ( Mouse : : LEFT ) . bReleased ) {
dragging = false ;
}
if ( GetKey ( HOME ) . bPressed ) {
edgeDetect = ! edgeDetect ;
}
if ( GetKey ( INS ) . bHeld ) {
edgeLowerThreshold = std : : clamp ( edgeLowerThreshold + fElapsedTime * 60 , 0.f , 255.f ) ;
}
if ( GetKey ( DEL ) . bHeld ) {
edgeLowerThreshold = std : : clamp ( edgeLowerThreshold - fElapsedTime * 60 , 0.f , 255.f ) ;
}
if ( GetKey ( PGUP ) . bHeld ) {
edgeUpperThreshold = std : : clamp ( edgeUpperThreshold + fElapsedTime * 60 , 0.f , 255.f ) ;
}
if ( GetKey ( PGDN ) . bHeld ) {
edgeUpperThreshold = std : : clamp ( edgeUpperThreshold - fElapsedTime * 60 , 0.f , 255.f ) ;
}
return true ;
}
} ;