保存时间:2026/4/2 08:27:47
cv::waitKey(0) 意味着无限期地等待键盘事件。这里的参数单位是毫秒,传入 0 就表示不会自动结束等待,程序会一直暂停,直到用户按下任意按键。要是你传入一个正整数,像 cv::waitKey(1000),这才是等待对应毫秒数(此例中是 1000 毫秒,也就是 1 秒)。cv::waitKey(0) 的常见用法:#include <opencv2/opencv.hpp>
#include <iostream>
int main() {
// 读取图像
cv::Mat image = cv::imread("example.jpg");
// 检查图像是否成功加载
if (image.empty()) {
std::cout << "无法加载图像" << std::endl;
return -1;
}
// 显示图像
cv::imshow("显示窗口", image);
// 无限期等待按键事件
cv::waitKey(0);
// 关闭所有窗口
cv::destroyAllWindows();
return 0;
}
cv::waitKey(0) 后,程序会暂停运行,等待用户按下任意按键。cv::waitKey(0) 的作用是无限期等待键盘输入,而不是等待 0 秒。cv::circle 函数的作用是在图像上绘制圆形。下面为你介绍它的参数以及使用示例:void cv::circle(
cv::InputOutputArray img, // 输入/输出图像(如cv::Mat)
cv::Point center, // 圆心坐标(x, y)
int radius, // 圆的半径(像素)
const cv::Scalar& color, // 圆的颜色,如CV_RGB(255,0,0)表示蓝色
int thickness = 1, // 线条粗细,-1表示填充
int lineType = cv::LINE_8, // 线条类型(如cv::LINE_AA为抗锯齿)
int shift = 0 // 坐标点的小数点位数
);
cv::Point(x, y)来指定,其中x和y是图像中的像素坐标。cv::Scalar(B, G, R)来表示,注意顺序是 B(蓝)、G(绿)、R(红)。比如cv::Scalar(0, 0, 255)代表红色。cv::LINE_8(8 连通线,默认值)和cv::LINE_AA(抗锯齿线,使圆看起来更平滑)。cv::circle函数:#include <opencv2/opencv.hpp>
int main() {
// 创建一个黑色背景的图像(500×500像素)
cv::Mat image = cv::Mat::zeros(500, 500, CV_8UC3);
// 绘制不同样式的圆
cv::Point center(250, 250); // 图像中心
// 绘制红色空心圆(线宽为2像素)
cv::circle(image, center, 100, cv::Scalar(0, 0, 255), 2);
// 绘制绿色填充圆
cv::circle(image, center, 50, cv::Scalar(0, 255, 0), -1);
// 绘制蓝色抗锯齿空心圆
cv::circle(image, cv::Point(400, 100), 30, cv::Scalar(255, 0, 0), 3, cv::LINE_AA);
// 显示结果
cv::imshow("绘制圆形", image);
cv::waitKey(0);
return 0;
}
thickness设为 - 1,所以圆是被填充的。cv::LINE_AA)让圆的边缘看起来更平滑。main branch identical to a specific branch using git rebase, follow these steps. However, note that rebasing is not the optimal method for this purpose; force pushing the specific branch to main is more efficient. Here's how to do both:main to exactly match feature-branch (discarding all main changes), use:git checkout feature-branch # Switch to the branch you want to copy
git push -f origin feature-branch:main # Force push to overwrite main
git push -f overwrites the remote main with feature-branch.main that aren’t in feature-branch. Use only if you’re certain.rebase (which is less efficient for this scenario), follow these steps:main and update it:git checkout main
git pull origin main # Ensure main is up-to-date
main onto feature-branch:git rebase feature-branch
main’s commits on top of feature-branch, but it’s redundant if main should be identical to feature-branch.main to the remote:git push -f origin main
main’s history and makes it identical to feature-branch.main’s commits on feature-branch, which is unnecessary if you want exact copies.main to match feature-branch:git checkout main
git reset --hard feature-branch # Reset main to feature-branch
git push -f origin main # Push to remote
main to exactly mirror feature-branch.feature-branch into main while preserving both branch histories.main branch identical to the HEAD of branch A (i.e., overwrite main with A's current state), use git reset followed by a force push (if needed). Here's how:maingit checkout main
main to Match Agit reset --hard to move main to the same commit as A's HEAD:git reset --hard A
--hard discards all changes in main and sets it to exactly match A.main branch:git push -f origin main
git push -f force-overwrites the remote main with your local main. Use with caution!A (HEAD) X---Y---Z
/
main X---A---B
git reset --hard A on main:main (HEAD) X---Y---Z
A X---Y---Z
main Without Checkoutmain first, use:git branch -f main A
git branch -f forces main to point to A's HEAD.main and push:git checkout main
git push -f origin main
git push -f only if you need to update the remote main.main deletes its previous commits. Ensure this is intentional.main) unless your team agrees.main matches A:git log --oneline main
git log --oneline A