对于视频中的对象检测,我们使用大小大于 1 的批次。但是在视频结束时,当剩余帧数少于批次大小时,我们会收到以下错误:
2018-06-07 15:31:26.456907: W tensorflow/core/framework/op_kernel.cc:1290] CtxFailure at image_resizer_state.h:84: Invalid argument: output dimensions must be positive
Run Code Online (Sandbox Code Playgroud)
为了读取视频,我们使用 Opencv 3.3.0,帧存储在向量中batch
for (size_t i = 0; i < batch_size; i++) {
ret = cap.read(readImage);
if (!ret) {
break;
}
batch.push_back(readImage.clone());
}
Run Code Online (Sandbox Code Playgroud)
该向量被转换为 tf 张量为
tensorflow::Tensor inputImg(
tensorflow::DT_UINT8,
tensorflow::TensorShape(
{static_cast<long long int>(batch.size()), height, width, depth}));
for (size_t i = 0; i < batch.size(); i++) {
auto tmp = inputImg.Slice(i, i + 1);
uint8_t *p = tmp.flat<uint8_t>().data();
cv::Mat cameraImg(height, width, CV_8UC3, p); …Run Code Online (Sandbox Code Playgroud)