Assigning uchar pixel going wrong
I want to set a pixel which meets certain criteria to 4096 (2^12), but what I end up with is 14;
Its an cv::Mat dImg
in the format 16UC1
for(int j=0;j<dImg.rows;j++)
{
uchar* pixrow = dImg.ptr<uchar>(j);
for (int i=0;i<dImg.cols;i++)
{
if(j == 240 && pixrow[i] ==0) dImg.at<uchar>(j,i) = 2^12;
also this results in cout=14:
if(j == 240 && pixrow[i] ==0) pixrow[i] = 2^12; //= 4096
I check the value with
cout<<"\nmodified: "<<endl;
for(int i = 0; i<dImg.cols;i++){
cout<<" "<<unsigned(dImg.at<uchar>(240,i));
}
SOLUTION (thank your for answering)
for(int j=0;j<dImg.rows;j++)
{
ushort* pixrow = dImg.ptr<ushort>(j); //not uchar
for (int i=0;i<dImg.cols;i++)
{
if(j == 239 && pixrow[i] ==0) pixrow[i] = 4096;