@rudycazabon wrote:
Greetings everyone -
I need to use ofVideoGrabber as opposed to OpenCV to VideoCapture. In previous code I wrote I used Mat::data to pull the actual pixel of the frame as a uchar* … and reading through the ofVideoGrabber::getPixels() call I see that it too returns a unsigned char*.
However, when it comes time to convert the incoming from ofVideoGrabber from RGB to BGR format I get a failure. The code I am using is as follows:
void ConvertBGR(
const size_t imageWidth,
const size_t imageHeight,
const std::vector<uint8_t*>& srcs,
float* dst,
const std::vector& mean,
const std::vector& scale)
{
const size_t channels = 3;
const size_t channelSize = imageWidth * imageHeight;
const size_t imageSize = channelSize * channels;float* rBuffer = &dst[channelSize * 0];
float* gBuffer = &dst[channelSize * 1];
float* bBuffer = &dst[channelSize * 2];const size_t rOff = 2;
const size_t gOff = 1;
const size_t bOff = 0;size_t idx = 0;
// swap the bytes
for (size_t mb = 0; mb < srcs.size(); mb++) {
const uint8_t* srcBuffer = srcs[mb];idx = imageSize * mb; for (size_t h = 0; h < imageHeight; h++) { size_t srcIdx = h * imageWidth * channels; for (size_t w = 0; w < imageWidth; w++, idx++, srcIdx += channels) { rBuffer[idx] = ((float)srcBuffer[srcIdx + rOff] - mean[0]) / scale[0]; gBuffer[idx] = ((float)srcBuffer[srcIdx + gOff] - mean[1]) / scale[1]; bBuffer[idx] = ((float)srcBuffer[srcIdx + bOff] - mean[2]) / scale[2]; } }
}
}My call to this function using ofVideoGrabber is as follows:
ofVideoGrabber grabber; < grabber initialization code > <success!!> ConvertBGR(inputWidth, inputHeight, { grabber.getPixels() }, inputPtr, mean, scale);
The call to this same function using OpenCV is successful. The call to this function from ofVideoGrabber.getPixels() fails rBuffer, gBuffer and bbuffer for access violations/memory not accessible.
Any and all comments and insights from the community would be greatly appreciated.
Regards,
RudyC
Posts: 1
Participants: 1