#include "viewer.h"
#include <opencv/cv.h>
#include <QPainter>
Viewer::Viewer(QWidget *parent) :
QWidget(parent)
{
m_imageBuf=NULL;
resize(parent->width(), parent->height());
widthRatio=1.0*width()/OrinCamWidth;
heighRatio=1.0*height()/OrinCamHeight;
double minRatio=(widthRatio<heighRatio)?widthRatio:heighRatio;
new_width=width()*minRatio;
new_height=height()*minRatio;
resize(new_width,new_height);
std::cout<<"parent->width()="<<parent->width()<<" ,width()= "<<width()<<" ,new_width= "<< new_width<<std::endl;
resizeImg = cvCreateImage(cvSize(new_width,new_height),IPL_DEPTH_8U, 3);
dispImg=cvCreateImageHeader(cvSize(new_width,new_height), IPL_DEPTH_8U, 3);
assert(dispImg);
paintQImage=new QImage(new_width,new_height, QImage::Format_RGB888);
currentSize = cvSize(new_width,new_height);
dispImg->imageData=(char*)paintQImage->bits();
widthRatio=1.0*new_width/720;
heighRatio=1.0*new_height/576;
ratiow=1;
ratioh=1;
state=IDEL;
objectSum=0;
setMouseTracking(true);
m_imageChanged=false;
drawRect_isDown = false;
crossline_enable=false;
slitrect_enable= true;
crosspoint.setX(width()/2);
crosspoint.setY(height()/2);
showcircle=false;
}
Viewer::~Viewer(){
cvReleaseImage(&resizeImg);
cvReleaseImageHeader(&dispImg);
}
void Viewer::receive_image(const IplImage* img){
assert(img);
assert(img->nChannels==3 && img->depth==IPL_DEPTH_8U);
if(!m_imageBuf)
m_imageBuf=cvCreateImage(cvGetSize(img), 8, 3);
else if(m_imageBuf->width!=img->width || m_imageBuf->height!=img->height){
cvReleaseImage(&m_imageBuf);
m_imageBuf=cvCreateImage(cvGetSize(img), 8, 3);
widthRatio=1.0*img->width /640;
heighRatio=1.0*img->height/480;
}
cvCopyImage(img, m_imageBuf);
cvCvtColor(m_imageBuf,m_imageBuf,CV_BGR2RGB);
if(resizeImg->width!=m_imageBuf->width || resizeImg->height!=m_imageBuf->height)
cvResize(m_imageBuf, resizeImg);
else
cvCopy(m_imageBuf, resizeImg);
if(m_imageBuf){
widthRatio=1.0*width()/m_imageBuf->width;
heighRatio=1.0*height()/m_imageBuf->height;
}
// std::cout<<widthRatio<<heighRatio<<std::endl;
m_imageChanged=true;
update();
}
void Viewer::paintEvent(QPaintEvent*){
if(m_imageChanged){
if(resizeImg->width!=new_width || resizeImg->height!=new_height){
cvReleaseImage(&resizeImg);
cvReleaseImageHeader(&dispImg);
delete paintQImage;
resizeImg=cvCreateImage(cvSize(new_width,new_height), 8, 3);
dispImg=cvCreateImageHeader(cvSize(new_width,new_height), 8, 3);
paintQImage=new QImage(new_width,new_height, QImage::Format_RGB888);
dispImg->imageData=(char*)paintQImage->bits();
}
if(m_imageBuf){
cvResize(m_imageBuf, resizeImg, CV_INTER_NN);
}
m_imageChanged=false;
}
cvCopy(resizeImg,dispImg);
// draw_frame(*paintQImage,patternCircleFrame, QPen(QColor(0,255,0)));
draw_frame(*paintQImage,patternFrame, QPen(QColor(255,5,255)));
if(crossline_enable)
draw_cross_line(*paintQImage);
QPainter painter(this);
painter.drawImage(QPoint(0,0),*paintQImage);
// if(slitrect_enable&&drawRect){
// painter.setPen(QPen(QColor(255, 0, 255)));
// painter.drawRect(QRect(pt1,pt2)); //画矩形框
// //enable=true;
// }
// if(drawRect_isDown){
// // QPoint point1,point2;
// //point1.setX();
// painter.setPen(QPen(QColor(255, 0, 255)));
// painter.drawRect(QRect(Rect_start,Rect_stop));
// //enable=false;
// }
}
void Viewer::draw_cross_line(QImage& qImage){
QPainter painter(&qImage);
QPen pen(QColor(0,0,255));
pen.setStyle(Qt::DashLine);
painter.setPen(pen);
painter.drawLine(0, crosspoint.y(), qImage.width(), crosspoint.y());
painter.drawLine(crosspoint.x(), 0, crosspoint.x(), qImage.height());
}
void Viewer::draw_ponit(QImage& qImage){
QPainter painter(&qImage);
QPen pen(QColor(0,255,0));
//pen.setStyle(Qt::DashLine);
painter.setPen(pen);
painter.drawLine(0,0,232,232);
//painter.drawLine(p1.x(),p1.y(),p3.x(),p3.y());
}
void Viewer::mousePressEvent(QMouseEvent *event){
if(event->button()==Qt::RightButton){
cursorx=event->pos().x();
cursory=event->pos().y();
//std::cout<<"right_press_point"<<cursorx<<" "<<cursory<<std::endl;
// emit left_press(cursorx, cursory);
event->accept();
}
else if(event->button()==Qt::LeftButton){
if(state==READY){
cursorx=event->pos().x();
cursory=event->pos().y();
//std::cout<<cursorx<<" "<<cursory<<std::endl;
state=CHANGING;
event->accept();
}
else {
drawRect_isDown = true;
drawRect=false;
Rect_start = event->pos();
Rect_stop = event->pos();
//std::cout<<Rect_start.x()<<" "<<Rect_start.y()<<std::endl;
}
}
}
void Viewer::mouseReleaseEvent(QMouseEvent *event){
if(event->button()==Qt::RightButton){
if(state==CHANGING)
state=READY;
}
if(event->button()==Qt::LeftButton){
if(state==CHANGING)
state=READY;
else if(drawRect_isDown){
if(Rect_stop.x()!=Rect_start.x()||Rect_stop.y()!=Rect_start.y()){
pt1.setX(crosspoint.x()-abs(Rect_start.x()-Rect_stop.x())*0.5);
pt1.setY(crosspoint.y()-abs(Rect_start.y()-Rect_stop.y())*0.5);
pt2.setX(crosspoint.x()+abs(Rect_start.x()-Rect_stop.x())*0.5);
pt2.setY(crosspoint.y()+abs(Rect_start.y()-Rect_stop.y())*0.5);
// emit rect_press(abs(Rect_stop.x()-Rect_start.x())/2+qMin(Rect_stop.x(),Rect_start.x()), abs(Rect_stop.y()-Rect_start.y())/2+qMin(Rect_stop.y(),Rect_start.y()),abs(Rect_stop.x()-Rect_start.x()),abs(Rect_stop.y()-Rect_start.y()));
//std::cout<<(abs(Rect_stop.x()-Rect_start.x())/2+qMin(Rect_stop.x(),Rect_start.x()))<<" "<<(abs(Rect_stop.y()-Rect_start.y())/2+qMin(Rect_stop.y(),Rect_start.y()))<<std::endl;
}
drawRect=true;
drawRect_isDown=false;
}
}
}
void Viewer::mouseMoveEvent(QMouseEvent *event){
// enum{IDEL, READY, CHANGING}state;
//std::cout<<"state is "<<state<<std::endl;
static RectangleFrame::ChangeType oldChangeType=RectangleFrame::nochange;
static CircleFrame::ChangeType oldCircleChangeType=CircleFrame::nochange;
QPoint pos= event->pos();
int x=pos.x();
int y=pos.y();
if(x<0 ||y<0 ||x>=width() ||y>=height()){
event->accept();
return;
}
if(state==READY){
RectangleFrame::ChangeType changeType;
CircleFrame::ChangeType changeCircleType;
if(showcircle){
changeCircleType=patternCircleFrame.get_ready_change_type(x,y,sensitiveRange);
//change the cursor shape
if(changeCircleType!=oldCircleChangeType){
oldCircleChangeType=changeCircleType;
switch(changeCircleType){
case CircleFrame::MOVE:
setCursor(Qt::SizeAllCursor);
break;
case CircleFrame::top:
case CircleFrame::bottom:
setCursor(Qt::SizeVerCursor);
break;
case CircleFrame::left:
case CircleFrame::right:
setCursor(Qt::SizeHorCursor);
break;
default: setCursor(Qt::ArrowCursor);
}
}
}
else{
没有合适的资源?快使用搜索试试~ 我知道了~
对视频中的画面进行截图
共29个文件
cpp:9个
o:9个
h:6个
需积分: 48 27 下载量 5 浏览量
2016-05-23
22:43:31
上传
评论
收藏 105KB ZIP 举报
温馨提示
程序利用QT在linux环境下搭建,功能为打开某个视频文件,并对视频画面中的图像进行捕捉并保存到本地文件,捕捉画面大小可以通过鼠标或数字输入来调节。可以用来扣取视频中的样本,例如在一个有车辆的视频中扣取车牌作为训练样本。
资源推荐
资源详情
资源评论
收起资源包目录
capture_vediopic.zip (29个子文件)
capture
newframe.o 14KB
moc_viewer.o 10KB
mainwindow.ui 5KB
moc_mainwindow.cpp 6KB
main.o 5KB
VIEW 96KB
viewer.o 24KB
localcam.o 4KB
moc_laserapp.o 11KB
moc_viewer.cpp 2KB
laserapp.o 19KB
mainwindow.cpp 4KB
laserapp.h 783B
mainwindow.o 24KB
camera
localcam.h 674B
newframe.h 3KB
newframe.cpp 12KB
localcam.cpp 2KB
viewer.cpp 15KB
VIEW.pro.user 27KB
main.cpp 216B
moc_laserapp.cpp 3KB
Makefile 9KB
moc_mainwindow.o 13KB
mainwindow.h 1KB
VIEW.pro 885B
ui_mainwindow.h 8KB
laserapp.cpp 4KB
viewer.h 2KB
共 29 条
- 1
资源评论
夏日里的猫
- 粉丝: 211
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功