# Cannot change pixel value of image

**URL:** <https://forum.opencv.org/t/cannot-change-pixel-value-of-image/2809>\
**Category:** C++\
**Tags:** mat, core\
**Created:** [April 17, 2021, 7:36am UTC](https://forum.opencv.org/t/cannot-change-pixel-value-of-image/2809 "2021-04-17T07:36:39Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [April 17, 2021, 7:51am UTC](https://forum.opencv.org/t/cannot-change-pixel-value-of-image/2809/2 "2021-04-17T07:51:15Z")

</div>

please do NOT write loops like that, they’re slow, error prone, and defeat the purpose of a high-level matrix library like opencv

you already got x,y wrong, it’s `at(row,col)` in opencv

please rather [copy a whole ROI](https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#a33fd5d125b4c302b0c9aa86980791a77), like in:

```
Rect child_rect(child.getX(),child.gety(),child.getW(),child.getH()));
final.copyTo(img2(child_rect));
```

---

_[View the full topic](https://forum.opencv.org/t/cannot-change-pixel-value-of-image/2809)._
