QString appPath = QCoreApplication::applicationDirPath(); imagePath = appPath + "/A.jpg"; img = cv::imread(imagePath.toStdString()); if (img.empty()) return; Mat bg = Mat::zeros(img.size(),img.type()); Rect rect; rect.x = 200; rect.y = 200; rect.width = 100; rect.height = 50; rectangle(bg, rect, Scalar(0, 0, 255), -1,8,0); circle(bg, Point(50, 100), 15, Scalar(255, 0, 0), 2); line(bg, Point(100, 100), Point(100, 200), Scalar(0, 255, 0), 2, LINE_AA, 0); RotatedRect rrt(Point(200, 200),Size(100, 200), 90.0); ellipse(bg, rrt, Scalar(0, 255, 255), 2, 8); Mat dst; addWeighted(img, 0.7,bg,0.3,0, dst); imshow("Draw", dst);