Last active
November 19, 2017 11:48
-
-
Save dkurt/c736ec8b3c2fd8210a85413bdb1ca468 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cv::Mat img = cv::imread("toucan.jpg"); | |
cv::resize(img, img, cv::Size(224, 224)); | |
img.convertTo(img, CV_32F); | |
cv::subtract(img, cv::Scalar(104.0f, 117.0f, 123.0f), img); | |
cv::divide(img, cv::Scalar(127.5f, 127.5f, 127.5f), img); | |
std::vector<cv::Mat> channels(3); | |
cv::split(img, channels); | |
cv::Mat blob({1, 3, 224, 224}, CV_32F); | |
for (int i = 0; i < 3; ++i) { | |
cv::Mat dst(224, 224, CV_32F, blob.ptr<float>(0, i)); | |
channels[i].copyTo(dst); | |
} | |
cv::Mat blob2 = cv::dnn::blobFromImage(cv::imread("toucan.jpg"), 1.0/127.5, cv::Size(224, 224), cv::Scalar(104, 117, 123), false, false); | |
cv::dnn::Net net = cv::dnn::readNetFromCaffe("/path/to/example.prototxt", "/path/to/example.caffemodel"); | |
net.setInput(blob); | |
cv::Mat out = net.forward(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment