cv::Mat image = cv::imread(bg_filesOfImages[j].c_str());
cv::Mat logo = cv::imread(filesOfImages[j].c_str());
cv::Mat imageROI;
int width = image.cols;
int height = image.rows;
int xpix = random(width-92);
int ypix = random(height-100);
if (xpix < 0)
{
xpix = -xpix;
}
else if (xpix == 0)
{
xpix = 1;
}
else
{
printf("x该值大于零!\n");
}
if (ypix < 0)
{
ypix = -ypix;
}
else if (ypix == 0)
{
ypix = 1;
}
else
{
printf("y该值大于零!\n");
}
char xPixStr[16] = { 0 };
char yPixStr[16] = { 0 };
char widthStr[16] = { 0 };
char heightStr[16] = { 0 };
_itoa(xpix, xPixStr, 10);
_itoa(ypix, yPixStr, 10);
_itoa(88, widthStr, 10);
_itoa(96, heightStr, 10);
ofs.write(xPixStr, strlen(xPixStr));
ofs.write(",", 1);
ofs.write(yPixStr, strlen(yPixStr));
ofs.write(",", 1);
ofs.write(widthStr, strlen(widthStr));
ofs.write(",", 1);
ofs.write(heightStr, strlen(heightStr));
ofs.write("\n", 1);
imageROI = image(cv::Rect(xpix, ypix, 88, 96));
logo.copyTo(imageROI, logo);
cv::namedWindow("result");
cv::imshow("result", image);
imwrite(bg_filesOfImages[j].c_str(), image);
cv::waitKey(33);
p图代码
最新推荐文章于 2024-03-08 15:22:49 发布