{"action":"closed","issue":{"url":"https://api.github.com/repos/Itseez/opencv/issues/5643","labels_url":"https://api.github.com/repos/Itseez/opencv/issues/5643/labels{/name}","comments_url":"https://api.github.com/repos/Itseez/opencv/issues/5643/comments","events_url":"https://api.github.com/repos/Itseez/opencv/issues/5643/events","html_url":"https://github.com/Itseez/opencv/issues/5643","id":115737666,"number":5643,"title":"[shape] wrong mat copy in ShapeContextDistanceExtractor::getImages","user":{"login":"amroamroamro","id":83908,"avatar_url":"https://avatars.githubusercontent.com/u/83908?v=3","gravatar_id":"","url":"https://api.github.com/users/amroamroamro","html_url":"https://github.com/amroamroamro","followers_url":"https://api.github.com/users/amroamroamro/followers","following_url":"https://api.github.com/users/amroamroamro/following{/other_user}","gists_url":"https://api.github.com/users/amroamroamro/gists{/gist_id}","starred_url":"https://api.github.com/users/amroamroamro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amroamroamro/subscriptions","organizations_url":"https://api.github.com/users/amroamroamro/orgs","repos_url":"https://api.github.com/users/amroamroamro/repos","events_url":"https://api.github.com/users/amroamroamro/events{/privacy}","received_events_url":"https://api.github.com/users/amroamroamro/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Itseez/opencv/labels/affected:%20master","name":"affected: master","color":"ededed"},{"url":"https://api.github.com/repos/Itseez/opencv/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/Itseez/opencv/labels/category:%20shape","name":"category: shape","color":"ededed"},{"url":"https://api.github.com/repos/Itseez/opencv/labels/priority:%20normal","name":"priority: normal","color":"A38700"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-08T14:45:47Z","updated_at":"2015-12-23T16:14:43Z","closed_at":"2015-12-23T16:14:43Z","body":"There's a small bug in `cv::ShapeContextDistanceExtractor::getImages`.\r\nHere is a simple example to reproduce it (tested in OpenCV 3.0.0, Win x64):\r\n\r\n``` cpp\r\n#include <iostream>\r\n#include \"opencv2/core.hpp\"\r\n#include \"opencv2/shape.hpp\"\r\nusing namespace std;\r\nusing namespace cv;\r\n\r\nint main()\r\n{\r\n    Mat img1(3, 4, CV_8UC1, Scalar::all(1));\r\n    Mat img2(3, 4, CV_8UC1, Scalar::all(2));\r\n\r\n    Ptr<ShapeContextDistanceExtractor> sc = createShapeContextDistanceExtractor();\r\n    sc->setImages(img1, img2);\r\n\r\n    Mat im1, im2;\r\n    sc->getImages(im1, im2);\r\n\r\n    cout << \"img1 = \\n\" << img1 << endl;\r\n    cout << \"im1 = \\n\" << im1 << endl;\r\n    // same thing with im2/img2\r\n\r\n    return 0;\r\n}\r\n```\r\n\r\nThe returned matrices are created but never filled (we get garbage values):\r\n```\r\nimg1 =\r\n[  1,   1,   1,   1;\r\n   1,   1,   1,   1;\r\n   1,   1,   1,   1]\r\nim1 =\r\n[  0,   0,   0,   0;\r\n  12, 106,  80,  32;\r\n  32,  13,  10, 135]\r\n```\r\n\r\nI believe the assignments on [these lines](https://github.com/Itseez/opencv/blob/master/modules/shape/src/sc_dis.cpp#L129) are incorrect :\r\n\r\n``` cpp\r\nvirtual void getImages(OutputArray _image1, OutputArray _image2) const\r\n{\r\n    CV_Assert((!image1.empty()) && (!image2.empty()));\r\n    _image1.create(image1.size(), image1.type());\r\n    _image2.create(image2.size(), image2.type());\r\n    _image1.getMat()=image1;   // <---\r\n    _image2.getMat()=image2;   // <---\r\n}\r\n```\r\n\r\nInstead maybe we should do something like:\r\n\r\n``` cpp\r\nvirtual void getImages(OutputArray _image1, OutputArray _image2) const\r\n{\r\n    CV_Assert((!image1.empty()) && (!image2.empty()));\r\n    image1.copyTo(_image1);\r\n    image2.copyTo(_image2);\r\n}\r\n```\r\n"}}