Qt 从图片中截取到需要的部分

努力的草根 2015-08-11 11:39:14
我在qgraphicsView放了一张图片,然后我想通过鼠标这张图片上画一个形状然后将这个形状里面的图片保存下来
...全文
2324 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
void MainWindow::caculate()
{
static int iCount = 1;
while(!_bStopped)
{
cv::Mat frame;
cv::Mat frameCalibration;

_videoCapture.read(frame);
if(_bCut)
{
_bCut = false;
cv::imwrite((QCoreApplication::applicationDirPath()+"/../pictures/"+QString::number(iCount)+".jpg").toStdString(), frame);
iCount++;
}
if(iCount > 20)
{
_timer->stop();
cv::destroyAllWindows();
return;
}
int64 start = QDateTime::currentMSecsSinceEpoch();
cv::remap(frame, frameCalibration, map1, map2, cv::INTER_LINEAR);
int64 end = QDateTime::currentMSecsSinceEpoch();
qDebug()<<start <<end <<end-start;

// cv::imshow("cut", frameCalibration);
cv::imshow("cut", frame);
cv::waitKey(1);
}
}

void MainWindow::on_pushButton_clicked()
{
//_bStopped = !_bStopped;
_bCut = true;
}
fyn272064949 2015-08-13
  • 打赏
  • 举报
回复
void Widget::mousePressEvent(QMouseEvent *e) { m_Path = QPainterPath(e->pos()); isEnd = false; } void Widget::mouseMoveEvent(QMouseEvent *e) { m_Path.lineTo(e->pos()); update(); } void Widget::mouseReleaseEvent(QMouseEvent *e) { m_Path.closeSubpath(); update(); isEnd = true; } void Widget::paintEvent(QPaintEvent *) { QPainter p(this); QImage temp("a.jpg"); p.drawImage(this->rect(), temp, temp.rect()); p.drawPath(m_Path); if(isEnd) { QPainterPath tempPath = m_Path; tempPath.translate(-tempPath.boundingRect().topLeft()); QImage img(m_Path.boundingRect().size().toSize(), QImage::Format_ARGB32); QPainter imgPainter(&img); imgPainter.setBackgroundMode(Qt::TransparentMode); QImage temp2 = temp.scaled(this->size()); temp2 = temp2.copy(m_Path.boundingRect().toRect()); imgPainter.fillPath(tempPath, QBrush(temp2)); img.save("temp.png"); isEnd = false; } } 我为何这么吊???? 代码没有优化, 自己去优化吧
彩阳 2015-08-11
  • 打赏
  • 举报
回复 1
QPixmap QPixmap::copy(int x, int y, int width, int height) const
QImage QImage::copy(int x, int y, int width, int height) const
随你所用。

16,817

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧