Wrong memory access at cv::Mat::at (Bug #1527)
Description
The code below
#include <cmath> #include <iostream> #include <opencv2\core\core.hpp> int main(int argc, char **argv) { cv::Mat res( 200, 200, CV_32FC3, cv::Scalar(0, 0, 0) ); res.at<cv::Vec3f>(100, 100) = cv::Vec3f(-9.1f, -9.1f, -9.1f); cv::Vec3f &color( res.at<cv::Vec3f>(100, 100) ); int t1( cvRound(std::exp( color.valr0 ) * 10) ); int t2( cvRound(std::exp( color.valr1 ) * 10) ); int t3( cvRound(std::exp( color.valr2 ) * 10) ); std::cout << colorr0 << "," << colorr1 << "," << colorr2 << std::endl; std::cout << t1 << "," << t2 << "," << t3 << std::endl; return 0; }
outputs
-9.1,-9.1,-9.1 0,0,10
but should
-9.1,-9.1,-9.1 0,0,0
The bug is present in Visual Studio 2010 (Win32, Console application, "Release" configuration, Floating point model: fast).
The bug is not present in "Floating point model: precise", or when optimization is turned off.
Examination of assembly code showed that last memory access (color.valr2) goes into neighboring (right) pixel, which is zero. So I get 10 instead of 0 for t3.
Associated revisions
Merge pull request #1527 from vpisarev:shape_module
History
Updated by Vadim Pisarevsky about 13 years ago
the bug can not be reproduced on my machine (Windows 7, VS2010 SP1 prof) with the latest trunk version, built in Release mode (32-bit configuration).
It's either the bug has been fixed since 2.3, or compiler settings are different, or because SP1 is installed.
- Status changed from Open to Done
- (deleted custom field) set to worksforme
Updated by Andrey Kamaev about 13 years ago
- Status changed from Done to Cancelled
Updated by Andrey Kamaev almost 13 years ago
- Target version set to 2.4.0