mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Set swapRB to false in Caffe tests and examples.
This commit is contained in:
+1
-1
@@ -86,7 +86,7 @@ public class MainActivity extends AppCompatActivity implements CvCameraViewListe
|
||||
// Forward image through network.
|
||||
Mat blob = Dnn.blobFromImage(frame, IN_SCALE_FACTOR,
|
||||
new Size(IN_WIDTH, IN_HEIGHT),
|
||||
new Scalar(MEAN_VAL, MEAN_VAL, MEAN_VAL), true);
|
||||
new Scalar(MEAN_VAL, MEAN_VAL, MEAN_VAL), false);
|
||||
net.setInput(blob);
|
||||
Mat detections = net.forward();
|
||||
|
||||
|
||||
@@ -91,21 +91,26 @@ int main(int argc, char **argv)
|
||||
String modelBin = "bvlc_googlenet.caffemodel";
|
||||
String imageFile = (argc > 1) ? argv[1] : "space_shuttle.jpg";
|
||||
|
||||
//! [Read and initialize network]
|
||||
Net net = dnn::readNetFromCaffe(modelTxt, modelBin);
|
||||
//! [Read and initialize network]
|
||||
|
||||
//! [Check that network was read successfully]
|
||||
if (net.empty())
|
||||
{
|
||||
std::cerr << "Can't load network by using the following files: " << std::endl;
|
||||
std::cerr << "prototxt: " << modelTxt << std::endl;
|
||||
std::cerr << "caffemodel: " << modelBin << std::endl;
|
||||
std::cerr << "bvlc_googlenet.caffemodel can be downloaded here:" << std::endl;
|
||||
std::cerr << "http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel" << std::endl;
|
||||
exit(-1);
|
||||
Net net;
|
||||
try {
|
||||
//! [Read and initialize network]
|
||||
net = dnn::readNetFromCaffe(modelTxt, modelBin);
|
||||
//! [Read and initialize network]
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
std::cerr << "Exception: " << e.what() << std::endl;
|
||||
//! [Check that network was read successfully]
|
||||
if (net.empty())
|
||||
{
|
||||
std::cerr << "Can't load network by using the following files: " << std::endl;
|
||||
std::cerr << "prototxt: " << modelTxt << std::endl;
|
||||
std::cerr << "caffemodel: " << modelBin << std::endl;
|
||||
std::cerr << "bvlc_googlenet.caffemodel can be downloaded here:" << std::endl;
|
||||
std::cerr << "http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel" << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
//! [Check that network was read successfully]
|
||||
}
|
||||
//! [Check that network was read successfully]
|
||||
|
||||
//! [Prepare blob]
|
||||
Mat img = imread(imageFile);
|
||||
@@ -115,9 +120,9 @@ int main(int argc, char **argv)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
//GoogLeNet accepts only 224x224 RGB-images
|
||||
Mat inputBlob = blobFromImage(img, 1, Size(224, 224),
|
||||
Scalar(104, 117, 123)); //Convert Mat to batch of images
|
||||
//GoogLeNet accepts only 224x224 BGR-images
|
||||
Mat inputBlob = blobFromImage(img, 1.0f, Size(224, 224),
|
||||
Scalar(104, 117, 123), false); //Convert Mat to batch of images
|
||||
//! [Prepare blob]
|
||||
|
||||
Mat prob;
|
||||
|
||||
@@ -113,8 +113,8 @@ int main(int argc, char **argv)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
resize(img, img, Size(500, 500)); //FCN accepts 500x500 RGB-images
|
||||
Mat inputBlob = blobFromImage(img); //Convert Mat to batch of images
|
||||
resize(img, img, Size(500, 500)); //FCN accepts 500x500 BGR-images
|
||||
Mat inputBlob = blobFromImage(img, 1, Size(), Scalar(), false); //Convert Mat to batch of images
|
||||
//! [Prepare blob]
|
||||
|
||||
//! [Set input blob]
|
||||
|
||||
@@ -11,7 +11,7 @@ def get_class_list():
|
||||
with open('synset_words.txt', 'rt') as f:
|
||||
return [x[x.find(" ") + 1:] for x in f]
|
||||
|
||||
blob = dnn.blobFromImage(cv2.imread('space_shuttle.jpg'), 1, (224, 224), (104, 117, 123))
|
||||
blob = dnn.blobFromImage(cv2.imread('space_shuttle.jpg'), 1, (224, 224), (104, 117, 123), false)
|
||||
print("Input:", blob.shape, blob.dtype)
|
||||
|
||||
net = dnn.readNetFromCaffe('bvlc_googlenet.prototxt', 'bvlc_googlenet.caffemodel')
|
||||
|
||||
@@ -41,7 +41,7 @@ if __name__ == "__main__":
|
||||
while True:
|
||||
# Capture frame-by-frame
|
||||
ret, frame = cap.read()
|
||||
blob = cv.dnn.blobFromImage(frame, inScaleFactor, (inWidth, inHeight), meanVal)
|
||||
blob = cv.dnn.blobFromImage(frame, inScaleFactor, (inWidth, inHeight), meanVal, false)
|
||||
net.setInput(blob)
|
||||
detections = net.forward()
|
||||
|
||||
|
||||
@@ -27,8 +27,7 @@ if __name__ == '__main__':
|
||||
cols = frame.shape[1]
|
||||
rows = frame.shape[0]
|
||||
|
||||
net.setInput(dnn.blobFromImage(cv.resize(frame, (inWidth, inHeight)),
|
||||
1.0, (inWidth, inHeight), (104., 177., 123.)))
|
||||
net.setInput(dnn.blobFromImage(frame, 1.0, (inWidth, inHeight), (104.0, 177.0, 123.0), false))
|
||||
detections = net.forward()
|
||||
|
||||
perf_stats = net.getPerfProfile()
|
||||
|
||||
@@ -97,7 +97,7 @@ int main(int argc, char** argv)
|
||||
//! [Prepare blob]
|
||||
|
||||
Mat inputBlob = blobFromImage(frame, inScaleFactor,
|
||||
Size(inWidth, inHeight), meanVal); //Convert Mat to batch of images
|
||||
Size(inWidth, inHeight), meanVal, false); //Convert Mat to batch of images
|
||||
//! [Prepare blob]
|
||||
|
||||
//! [Set input blob]
|
||||
|
||||
@@ -86,7 +86,7 @@ int main(int argc, char** argv)
|
||||
//! [Prepare blob]
|
||||
Mat preprocessedFrame = preprocess(frame);
|
||||
|
||||
Mat inputBlob = blobFromImage(preprocessedFrame); //Convert Mat to batch of images
|
||||
Mat inputBlob = blobFromImage(preprocessedFrame, 1.0f, Size(), Scalar(), false); //Convert Mat to batch of images
|
||||
//! [Prepare blob]
|
||||
|
||||
//! [Set input blob]
|
||||
|
||||
Reference in New Issue
Block a user