Problems creating a chroma key without mask on C++

Hi. I’m a student of Computer Science, and I’m doing a project in which i must to do a chroma key on a real time video, using RGB byte vectors. I have develop these code but did not work.

void CET21CanalAlphaDlg::OnBnClickedChroma()
for (int y = 0; y < frame.rows;y++) {
for (int x = 0;x < frame.cols;x++) {

		Vec3b& bgra =<Vec3b>(y, x);
		bgra[0] = 0;
		bgra[1] = 0;
		bgra[2] = 0;<Vec3b>(y, x) = bgra;


I’m trying to see the all pixels of the video black, in order to have a first approach to the final result.

Why do you mean by it does not work?
Vec3b is three byte. Are you sure that frame got three channel?

I can replace your code with one line

Don’t use loop to access pixel

you can but it’s a bad idea because OpenCV gives you means that are faster (.setTo as mentioned), so you can avoid writing your own loops.

I tried also that, but it do not work, I mean as I am working with my camera, when I use the setTo function do not show any change. That’s the code for showing the camera:

void CET21CanalAlphaDlg::OnTimer(UINT_PTR nIDEvent)
if (cap.isOpened()) {;
imshow(“Live”, frame);
if (videoOut.isOpened()) {




void CET21CanalAlphaDlg::OnBnClickedOk2()

if (!m_bCapturando) {
	if (archivovideo.IsEmpty()) {;
	else {
		std::string ss;
		ss = CW2A((LPCTSTR)archivovideo);;
	if (!cap.isOpened()) {
		AfxMessageBox(_T("Imposible abrir camara o video"), MB_OK);
	SetTimer(1, (uint)(10000.0 / fps), NULL);
	m_bCapturando = true;
else {
	m_bCapturando = false;