gpt4 book ai didi

opencv - opencv可以在cv::Mat中绘制浮点坐标矩形吗?

转载 作者:行者123 更新时间:2023-12-02 17:56:03 26 4
gpt4 key购买 nike

我正在尝试使用cv::rectangle()在cv::Mat中绘制一个rect,但是我可以绘制一个四点坐标值具有浮点精度的rect吗? (就像Qt在QPainter中所做的一样)。

最佳答案

快速尝试Blend2d库,并使用OpenCV轻松集成:
简单的例子:

#include <blend2d.h>
#include "opencv2/opencv.hpp"

int main(int argc, char* argv[])
{
BLImage img(480, 480, BL_FORMAT_PRGB32);
BLContext ctx(img);

// Read an image from file.
cv::Mat I = cv::imread("F:/ImagesForTest/lena.jpg");
cv::cvtColor(I, I, cv::COLOR_RGB2RGBA);
BLImage texture;
//BLResult err = texture.readFromFile("texture.jpeg");
texture.create(512, 512, BL_FORMAT_XRGB32);

memcpy((uchar*)texture.impl->pixelData, (uchar*)I.data, 512 * 512 * 4);
// Create a pattern and use it to fill a rounded-rect.
BLPattern pattern(texture);
ctx.setFillStyle(pattern);

ctx.setCompOp(BL_COMP_OP_SRC_COPY);
ctx.fillAll();

// Coordinates can be specified now or changed later.
BLGradient linear(BLLinearGradientValues(0, 0, 0, 480));


// Color stops can be added in any order.
linear.addStop(0.0, BLRgba32(0xFFFFFFFF));
linear.addStop(0.5, BLRgba32(0xFF5FAFDF));
linear.addStop(1.0, BLRgba32(0xFF2F5FDF));

// `setFillStyle()` can be used for both colors and styles.
ctx.setFillStyle(linear);




ctx.setCompOp(BL_COMP_OP_MODULATE);
ctx.fillRoundRect(40.0, 40.0, 400.0, 400.0, 45.5);

ctx.setStrokeStyle(BLRgba32(0xFFFF0000));
ctx.setStrokeWidth(3);
ctx.strokeLine(0,0,480,480);
ctx.end();

//BLImageCodec codec;
//codec.findByName("BMP");
//img.writeToFile("bl-getting-started-2.bmp", codec);

cv::Mat cvImg(img.height(), img.width(), CV_8UC4, img.impl->pixelData);
cv::imshow("res", cvImg);
cv::waitKey(0);

return 0;
}

关于opencv - opencv可以在cv::Mat中绘制浮点坐标矩形吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64639396/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com