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 = frame.at<Vec3b>(y, x);
		bgra[0] = 0;
		bgra[1] = 0;
		bgra[2] = 0;
		frame.at<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.

Hi,
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
frame.setTo(bgra);

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()) {
cap.read(frame);
imshow(“Live”, frame);
if (videoOut.isOpened()) {

			videoOut.write(frame);
		}
	
}
CDialogEx::OnTimer(nIDEvent);

}

and

void CET21CanalAlphaDlg::OnBnClickedOk2()
{
UpdateData(TRUE);

if (!m_bCapturando) {
	if (archivovideo.IsEmpty()) {
		cap.open(idcamara);
	}
	else {
		std::string ss;
		ss = CW2A((LPCTSTR)archivovideo);
		cap.open(ss);
	}
	if (!cap.isOpened()) {
		AfxMessageBox(_T("Imposible abrir camara o video"), MB_OK);
		return;
	}
	SetTimer(1, (uint)(10000.0 / fps), NULL);
	GetDlgItem(IDOK2)->SetWindowTextW(_T("Parar"));
	m_bCapturando = true;
}
else {
	KillTimer(1);
	GetDlgItem(IDOK2)->SetWindowTextW(_T("Capturar"));
	m_bCapturando = false;
}

}