Reputation: 19
I have created a variable hisTotF like
cv::Mat hisTotF=cv::Mat(1,60,CV_64FC1,Scalar(0));
I am trying to initialize the elements to zero. When I compile this program runs fine but when I run it then while initializing the 6th element in the array it gives a "Heap exception". I am trying to initialize the elements to zero by the command histTotF.at<double>(1,6)=0
.
Am I running out of memory. The program excited with the code 0xC0000374
. I am running OpenCV in Visual Studio 2012.
Upvotes: 0
Views: 335
Reputation: 20264
histTotF.at<double>(1,6) = 0;
This mean the pixel at the second row and the seventh column. You have only one row so you should use:
histTotF.at<double>(0,6) = 0;
in order to edit the pixel at the first row and the seventh column. Indecies are zero-based in cv::Mat
.
Anyway, constructing cv::Mat
using:
cv::Mat hisTotF=cv::Mat(1,60,CV_64FC1,Scalar(0));
is enough to make it all zeros.
If you want to go through all of the pixels in one row and change their values in fast way way, you may use cv::Mat::ptr
:
auto row_ptr = hisToF.ptr<double>(0); //Pointer to the first row.
for(size_t col_idx=0; col_idx<hisToF.cols; ++hisToF.cols){
row_ptr[col_idx]= 0; // Or whatever value you want
}
Upvotes: 1