We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我要想实现的是如果输入源是视频流,则获取到的每一帧先分割成小图片,然后小图片再送入batch进行推理,并返回推理的类别 我修改了task的返回值为类型,返回一个存储类别的列表 我遇到的问题是:
int rows = 16; int cols = 9;
while (capture.isOpened()) { if (batchi >= total_batches && source != utils::InputStream::CAMERA) { break; }
// 如果输入源是视频流或摄像头 if (source != utils::InputStream::IMAGE) { capture.read(frame); if (frame.empty()) { sample::gLogWarning << "no more video or camera frame" << std::endl; break; } // 计算新的宽度和高度 int newWidth = ((frame.cols / cols) * cols); if (newWidth < frame.cols) newWidth += cols; int newHeight = ((frame.rows / rows) * rows); if (newHeight < frame.rows) newHeight += rows; // 调整图像大小 cv::resize(frame, frame, cv::Size(newWidth, newHeight)); int width = newWidth / cols; int height = newHeight / rows; for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { cv::Rect roi(j * width, i * height, width, height); subFrames.push_back(frame(roi).clone()); } } // 将子图片逐个加入到imgs_batch中 for (auto& subFrame : subFrames) { if (imgs_batch.size() < param.batch_size) { imgs_batch.emplace_back(subFrame); } else { // 如果达到批次大小,执行推理并清空批次 auto predictions = task(yolo, param, imgs_batch, delay_time, batchi, is_show, is_save); imgs_batch.clear(); batchi++; // Print the predictions for (size_t bi = 0; bi < predictions.size(); bi++) { int classId = predictions[bi].first; std::cout << "Image " << bi << ": Predicted Class ID: " << classId << std::endl; } } } } else { // 如果输入源是单张图片 frame = cv::imread(image_path); if (!frame.empty()) { imgs_batch.emplace_back(frame); if (imgs_batch.size() == param.batch_size) { auto predictions = task(yolo, param, imgs_batch, delay_time, batchi, is_show, is_save); imgs_batch.clear(); batchi++; // Print the predictions for (size_t bi = 0; bi < predictions.size(); bi++) { int classId = predictions[bi].first; std::cout << "Image " << bi << ": Predicted Class ID: " << classId << std::endl; } } } } // 如果imgs_batch未满但所有子图片已添加完毕 if (source != utils::InputStream::IMAGE && !subFrames.empty() && imgs_batch.size() > 0) { auto predictions = task(yolo, param, imgs_batch, delay_time, batchi, is_show, is_save); imgs_batch.clear(); batchi++; // Print the predictions for (size_t bi = 0; bi < predictions.size(); bi++) { int classId = predictions[bi].first; std::cout << "Image " << bi << ": Predicted Class ID: " << classId << std::endl; } }
}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
我要想实现的是如果输入源是视频流,则获取到的每一帧先分割成小图片,然后小图片再送入batch进行推理,并返回推理的类别
我修改了task的返回值为类型,返回一个存储类别的列表
我遇到的问题是:
int rows = 16;
int cols = 9;
while (capture.isOpened()) {
if (batchi >= total_batches && source != utils::InputStream::CAMERA) {
break;
}
}
The text was updated successfully, but these errors were encountered: