|
|
@ -9,48 +9,46 @@ using namespace cv::dnn; |
|
|
|
#include <cstdlib> |
|
|
|
#include <cstdlib> |
|
|
|
using namespace std; |
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
|
|
static const string fcnType = "fcn8s"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//static void colorizeSegmentation(dnn::Blob& score,
|
|
|
|
static void colorizeSegmentation(dnn::Blob& score, |
|
|
|
// const vector<cv::Vec3b>& colors,
|
|
|
|
const vector<cv::Vec3b>& colors, |
|
|
|
// cv::Mat& segm)
|
|
|
|
cv::Mat& segm) |
|
|
|
//{
|
|
|
|
{ |
|
|
|
// const int rows = score.rows();
|
|
|
|
const int rows = score.rows(); |
|
|
|
// const int cols = score.cols();
|
|
|
|
const int cols = score.cols(); |
|
|
|
// const int chns = score.channels();
|
|
|
|
const int chns = score.channels(); |
|
|
|
|
|
|
|
|
|
|
|
// cv::Mat maxCl(rows, cols, CV_8UC1);
|
|
|
|
cv::Mat maxCl(rows, cols, CV_8UC1); |
|
|
|
// cv::Mat maxVal(rows, cols, CV_32FC1);
|
|
|
|
cv::Mat maxVal(rows, cols, CV_32FC1); |
|
|
|
// for (int ch = 0; ch < chns; ch++)
|
|
|
|
for (int ch = 0; ch < chns; ch++) |
|
|
|
// {
|
|
|
|
{ |
|
|
|
// for (int row = 0; row < rows; row++)
|
|
|
|
for (int row = 0; row < rows; row++) |
|
|
|
// {
|
|
|
|
{ |
|
|
|
// const float* ptrScore = score.ptrf(0, ch, row);
|
|
|
|
const float* ptrScore = score.ptrf(0, ch, row); |
|
|
|
// uchar* ptrMaxCl = maxCl.ptr<uchar>(row);
|
|
|
|
uchar* ptrMaxCl = maxCl.ptr<uchar>(row); |
|
|
|
// float* ptrMaxVal = maxVal.ptr<float>(row);
|
|
|
|
float* ptrMaxVal = maxVal.ptr<float>(row); |
|
|
|
// for (int col = 0; col < cols; col++)
|
|
|
|
for (int col = 0; col < cols; col++) |
|
|
|
// {
|
|
|
|
{ |
|
|
|
// if (ptrScore[col] > ptrMaxVal[col])
|
|
|
|
if (ptrScore[col] > ptrMaxVal[col]) |
|
|
|
// {
|
|
|
|
{ |
|
|
|
// ptrMaxVal[col] = ptrScore[col];
|
|
|
|
ptrMaxVal[col] = ptrScore[col]; |
|
|
|
// ptrMaxCl[col] = ch;
|
|
|
|
ptrMaxCl[col] = ch; |
|
|
|
// }
|
|
|
|
} |
|
|
|
// }
|
|
|
|
} |
|
|
|
// }
|
|
|
|
} |
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// segm.create(rows, cols, CV_8UC3);
|
|
|
|
segm.create(rows, cols, CV_8UC3); |
|
|
|
// for (int row = 0; row < rows; row++)
|
|
|
|
for (int row = 0; row < rows; row++) |
|
|
|
// {
|
|
|
|
{ |
|
|
|
// const uchar* ptrMaxCl = maxCl.ptr<uchar>(row);
|
|
|
|
const uchar* ptrMaxCl = maxCl.ptr<uchar>(row); |
|
|
|
// cv::Vec3b* ptrSegm = segm.ptr<cv::Vec3b>(row);
|
|
|
|
cv::Vec3b* ptrSegm = segm.ptr<cv::Vec3b>(row); |
|
|
|
// for (int col = 0; col < cols; col++)
|
|
|
|
for (int col = 0; col < cols; col++) |
|
|
|
// {
|
|
|
|
{ |
|
|
|
// ptrSegm[col] = colors[ptrMaxCl[col]];
|
|
|
|
ptrSegm[col] = colors[ptrMaxCl[col]]; |
|
|
|
// }
|
|
|
|
} |
|
|
|
// }
|
|
|
|
} |
|
|
|
//}
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char* about = "This sample uses Single-Shot Detector to detect objects " |
|
|
|
const char* about = "This sample uses Single-Shot Detector to detect objects " |
|
|
|
"from camera\n"; // TODO: link
|
|
|
|
"from camera\n"; // TODO: link
|
|
|
@ -111,6 +109,7 @@ int main(int argc, char** argv) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t i = 0; |
|
|
|
for (;; ) |
|
|
|
for (;; ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Mat frame; |
|
|
|
Mat frame; |
|
|
@ -118,12 +117,15 @@ int main(int argc, char** argv) |
|
|
|
if (frame.empty()) |
|
|
|
if (frame.empty()) |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! [Prepare blob]
|
|
|
|
//! [Prepare blob]
|
|
|
|
resize(frame, frame, Size(300, 300)); //SSD accepts 300x300 RGB-images
|
|
|
|
resize(frame, frame, Size(300, 300)); //SSD accepts 300x300 RGB-images
|
|
|
|
dnn::Blob inputBlob = dnn::Blob(frame); //Convert Mat to dnn::Blob image
|
|
|
|
dnn::Blob inputBlob = dnn::Blob(frame); //Convert Mat to dnn::Blob image
|
|
|
|
//! [Prepare blob]
|
|
|
|
//! [Prepare blob]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::ostringstream stream; |
|
|
|
|
|
|
|
stream << "folder/" << i << ".jpg"; |
|
|
|
|
|
|
|
imwrite(stream.str(), frame); |
|
|
|
|
|
|
|
|
|
|
|
//! [Set input blob]
|
|
|
|
//! [Set input blob]
|
|
|
|
net.setBlob(".data", inputBlob); //set the network input
|
|
|
|
net.setBlob(".data", inputBlob); //set the network input
|
|
|
|
//! [Set input blob]
|
|
|
|
//! [Set input blob]
|
|
|
@ -132,20 +134,20 @@ int main(int argc, char** argv) |
|
|
|
net.forward(); //compute output
|
|
|
|
net.forward(); //compute output
|
|
|
|
//! [Make forward pass]
|
|
|
|
//! [Make forward pass]
|
|
|
|
|
|
|
|
|
|
|
|
//! [Gather output]
|
|
|
|
// //! [Gather output]
|
|
|
|
dnn::Blob detection = net.getBlob("detection_out"); |
|
|
|
// dnn::Blob detection = net.getBlob("detection_out");
|
|
|
|
|
|
|
|
|
|
|
|
// cv::Mat colorize;
|
|
|
|
// // cv::Mat colorize;
|
|
|
|
// colorizeSegmentation(score, colors, colorize);
|
|
|
|
// // colorizeSegmentation(score, colors, colorize);
|
|
|
|
// cv::Mat show;
|
|
|
|
// // cv::Mat show;
|
|
|
|
// cv::addWeighted(img, 0.4, colorize, 0.6, 0.0, show);
|
|
|
|
// // cv::addWeighted(img, 0.4, colorize, 0.6, 0.0, show);
|
|
|
|
// cv::imshow("show", show);
|
|
|
|
// // cv::imshow("show", show);
|
|
|
|
// cv::waitKey(0);
|
|
|
|
// // cv::waitKey(0);
|
|
|
|
// return 0;
|
|
|
|
// // return 0;
|
|
|
|
|
|
|
|
|
|
|
|
imshow("frame", frame); |
|
|
|
// imshow("frame", frame);
|
|
|
|
if (waitKey(1) == 27) |
|
|
|
// if (waitKey(1) == 27)
|
|
|
|
break; // stop capturing by pressing ESC
|
|
|
|
// break; // stop capturing by pressing ESC
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
camera.release(); |
|
|
|
camera.release(); |
|
|
|