Add Canny Edge Detection Algorithm.
This commit is contained in:
parent
ff39c9fc95
commit
61030ccffe
@ -79,9 +79,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<cv::Mat>frames;
|
cv::Mat edges;
|
||||||
float frameView=0;
|
float frameView=0;
|
||||||
cv::VideoCapture video; // open the video file
|
cv::VideoCapture video; // open the video file
|
||||||
|
bool edgeDetect=true;
|
||||||
|
float edgeLowerThreshold=150;
|
||||||
|
float edgeUpperThreshold=255;
|
||||||
bool OnUserCreate() override
|
bool OnUserCreate() override
|
||||||
{
|
{
|
||||||
// Called once at the start, so create things here
|
// Called once at the start, so create things here
|
||||||
@ -92,6 +95,15 @@ public:
|
|||||||
void UpdateScreen(){
|
void UpdateScreen(){
|
||||||
Clear(BLACK);
|
Clear(BLACK);
|
||||||
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){
|
||||||
|
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 y=0;y<targetFrame.rows;y++){
|
||||||
for(int x=0;x<targetFrame.cols;x++){
|
for(int x=0;x<targetFrame.cols;x++){
|
||||||
cv::Vec3b col=targetFrame.at<cv::Vec3b>(y,x);
|
cv::Vec3b col=targetFrame.at<cv::Vec3b>(y,x);
|
||||||
@ -99,6 +111,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
vf2d upperLeft={-1,-1};
|
vf2d upperLeft={-1,-1};
|
||||||
vf2d lowerRight={-1,-1};
|
vf2d lowerRight={-1,-1};
|
||||||
bool cabDetected=false;
|
bool cabDetected=false;
|
||||||
@ -124,8 +137,9 @@ public:
|
|||||||
}
|
}
|
||||||
if(!cabDetected){
|
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);
|
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});
|
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(GetMouse(Mouse::LEFT).bPressed){
|
||||||
if(!dragging){
|
if(!dragging){
|
||||||
@ -139,6 +153,21 @@ public:
|
|||||||
if(GetMouse(Mouse::LEFT).bReleased){
|
if(GetMouse(Mouse::LEFT).bReleased){
|
||||||
dragging=false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user