mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-17 15:26:00 +08:00
Fix codestyle in structured_edge_detection sample
This commit is contained in:
@@ -7,6 +7,7 @@ https://github.com/opencv/opencv_extra/blob/master/testdata/cv/ximgproc/model.ym
|
||||
#include <opencv2/ximgproc.hpp>
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::ximgproc;
|
||||
@@ -21,52 +22,51 @@ const char* keys =
|
||||
int main( int argc, const char** argv )
|
||||
{
|
||||
bool printHelp = ( argc == 1 );
|
||||
printHelp = printHelp || ( argc == 2 && std::string(argv[1]) == "--help" );
|
||||
printHelp = printHelp || ( argc == 2 && std::string(argv[1]) == "-h" );
|
||||
printHelp = printHelp || ( argc == 2 && String(argv[1]) == "--help" );
|
||||
printHelp = printHelp || ( argc == 2 && String(argv[1]) == "-h" );
|
||||
|
||||
if ( printHelp )
|
||||
{
|
||||
printf("\nThis sample demonstrates structured forests for fast edge detection\n"
|
||||
std::cout << "\nThis sample demonstrates structured forests for fast edge detection\n"
|
||||
"Call:\n"
|
||||
" structured_edge_detection -i=in_image_name -m=model_name [-o=out_image_name]\n\n");
|
||||
" structured_edge_detection -i=in_image_name -m=model_name [-o=out_image_name]\n\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
cv::CommandLineParser parser(argc, argv, keys);
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
if ( !parser.check() )
|
||||
{
|
||||
parser.printErrors();
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string modelFilename = parser.get<std::string>("m");
|
||||
std::string inFilename = parser.get<std::string>("i");
|
||||
std::string outFilename = parser.get<std::string>("o");
|
||||
String modelFilename = parser.get<String>("m");
|
||||
String inFilename = parser.get<String>("i");
|
||||
String outFilename = parser.get<String>("o");
|
||||
|
||||
cv::Mat image = cv::imread(inFilename, 1);
|
||||
Mat image = imread(inFilename, 1);
|
||||
if ( image.empty() )
|
||||
{
|
||||
printf("Cannot read image file: %s\n", inFilename.c_str());
|
||||
return -1;
|
||||
}
|
||||
CV_Error(Error::StsError, String("Cannot read image file: ") + inFilename);
|
||||
|
||||
image.convertTo(image, cv::DataType<float>::type, 1/255.0);
|
||||
if ( modelFilename.size() == 0)
|
||||
CV_Error(Error::StsError, String("Empty model name"));
|
||||
|
||||
cv::Mat edges(image.size(), image.type());
|
||||
image.convertTo(image, DataType<float>::type, 1/255.0);
|
||||
|
||||
cv::Ptr<StructuredEdgeDetection> pDollar =
|
||||
Mat edges(image.size(), image.type());
|
||||
|
||||
Ptr<StructuredEdgeDetection> pDollar =
|
||||
createStructuredEdgeDetection(modelFilename);
|
||||
pDollar->detectEdges(image, edges);
|
||||
|
||||
if ( outFilename == "" )
|
||||
if ( outFilename.size() == 0 )
|
||||
{
|
||||
cv::namedWindow("edges", 1);
|
||||
cv::imshow("edges", edges);
|
||||
|
||||
cv::waitKey(0);
|
||||
namedWindow("edges", 1);
|
||||
imshow("edges", edges);
|
||||
waitKey(0);
|
||||
}
|
||||
else
|
||||
cv::imwrite(outFilename, 255*edges);
|
||||
imwrite(outFilename, 255*edges);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user