mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-21 14:41:58 +08:00
Updating of googlenet sample
This commit is contained in:
@@ -88,19 +88,12 @@ int main(int argc, char **argv)
|
|||||||
String modelBin = "bvlc_googlenet.caffemodel";
|
String modelBin = "bvlc_googlenet.caffemodel";
|
||||||
String imageFile = (argc > 1) ? argv[1] : "space_shuttle.jpg";
|
String imageFile = (argc > 1) ? argv[1] : "space_shuttle.jpg";
|
||||||
|
|
||||||
//! [Create the importer of Caffe model]
|
//! [Read and initialize network]
|
||||||
Ptr<dnn::Importer> importer;
|
Net net = dnn::readNetFromCaffe(modelTxt, modelBin);
|
||||||
try //Try to import Caffe GoogleNet model
|
//! [Read and initialize network]
|
||||||
{
|
|
||||||
importer = dnn::createCaffeImporter(modelTxt, modelBin);
|
|
||||||
}
|
|
||||||
catch (const cv::Exception &err) //Importer can throw errors, we will catch them
|
|
||||||
{
|
|
||||||
std::cerr << err.msg << std::endl;
|
|
||||||
}
|
|
||||||
//! [Create the importer of Caffe model]
|
|
||||||
|
|
||||||
if (!importer)
|
//! [Check that net was read successfully]
|
||||||
|
if (net.empty())
|
||||||
{
|
{
|
||||||
std::cerr << "Can't load network by using the following files: " << std::endl;
|
std::cerr << "Can't load network by using the following files: " << std::endl;
|
||||||
std::cerr << "prototxt: " << modelTxt << std::endl;
|
std::cerr << "prototxt: " << modelTxt << std::endl;
|
||||||
@@ -109,12 +102,7 @@ int main(int argc, char **argv)
|
|||||||
std::cerr << "http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel" << std::endl;
|
std::cerr << "http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel" << std::endl;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
//! [Check that net was read successfully]
|
||||||
//! [Initialize network]
|
|
||||||
dnn::Net net;
|
|
||||||
importer->populateNet(net);
|
|
||||||
importer.release(); //We don't need importer anymore
|
|
||||||
//! [Initialize network]
|
|
||||||
|
|
||||||
//! [Prepare blob]
|
//! [Prepare blob]
|
||||||
Mat img = imread(imageFile);
|
Mat img = imread(imageFile);
|
||||||
|
Reference in New Issue
Block a user