怎么样可以实现通过用鼠标在图像上画矩形来提取图像数据?
我现在想在回放视频流(avi)时通过用鼠标在屏幕上画一个矩形,把这一帧中的这个矩形中的图像数据提取出来,生成一个新的BMP图像? 问题点数:0、回复次数:7Top
1 楼zilili2000(桃花岛主)回复于 2004-12-03 15:16:51 得分 0
有些难度,
我做过在静止的图片上直接划矩形取图像数据,
在avi上直接取图还没见过,
关注。。。Top
2 楼marwb()回复于 2004-12-06 10:24:50 得分 0
我的思路是这样大,播放AVI 我使用的是Direct show中的filter。然后使用filter的接口IBasicVideo::GetCurrentImage来抓取其中的一帧,作为静态图像来处理。后面的处理基本上和静态是一样的了。
不知道 楼上是怎么从静态图像中通过鼠标画矩形来获取矩形区域的图像数据的?Top
3 楼51flyou(握心藏蛋)回复于 2004-12-06 14:49:03 得分 0
在avi上取图可不可以这样?
当鼠标由down到up时开始开始抓取一帧,此时记录鼠标down ,up的位置.用此位置来载取抓取的帧的数据。得到的数据就是所抓图的数据段,然后由此数据生成bmp图。Top
4 楼xiaoxiaofei(小小飞)回复于 2004-12-06 17:22:44 得分 0
动态选区没试过,不清楚,静态的要看是什么数据格式了.总的来说,你把位于矩形区域内部的数据提取出来另存就可以了,提取方式依赖于图形的数据格式.Top
5 楼marwb()回复于 2004-12-07 10:14:50 得分 0
可以啊,
我就是这样实现的,不过其实我是先将一帧完全抓下来后,再取图,不过有个问题,就是好像取出来的位置不对,可能是坐标系搞错,有没有人可以给我讲一下,屏幕坐标和AVI中的坐标系是怎么转化的?Top
6 楼xiaoxiaofei(小小飞)回复于 2004-12-07 14:41:11 得分 0
8知道什么叫AVI,不过你可以自己测试一下:随便画一条线,经过坐标转换,看它的端点坐标的变化,不就知道了?Top
7 楼gwycsdn()回复于 2004-12-14 14:01:17 得分 0
给你一段代码,相信对你有帮助
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
bool gbMDown=false;
TRect grtLTRB;
#define IMAGE_WIDTH 400
#define IMAGE_HEIGHT 400
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Panel1->Width=IMAGE_WIDTH+2*2;
Panel1->Height=IMAGE_HEIGHT+2*2;
Panel1->DoubleBuffered=true;
Panel2->Width=IMAGE_WIDTH+2*2;
Panel2->Height=IMAGE_HEIGHT+2*2;
Image1->Width=IMAGE_WIDTH;
Image1->Height=IMAGE_HEIGHT;
Image1->Left=(Panel1->Width-Image1->Width)/2;
Image1->Top=(Panel1->Height-Image1->Height)/2;
Image1->Stretch=true;
Image1->Picture->Bitmap->LoadFromFile("16bit-400x400.bmp");
PaintBox2->Width=IMAGE_WIDTH;
PaintBox2->Height=IMAGE_HEIGHT;
PaintBox2->Left=(Panel1->Width-PaintBox2->Width)/2;
PaintBox2->Top=(Panel1->Height-PaintBox2->Height)/2;
Image3->Width=IMAGE_WIDTH;
Image3->Height=IMAGE_HEIGHT;
Image3->Left=(Panel2->Width-Image3->Width)/2;
Image3->Top=(Panel2->Height-Image3->Height)/2;
Image3->Stretch=true;
Image3->Canvas->Brush->Color=clWhite;
Image3->Canvas->FillRect(Rect(0, 0, Image3->Width, Image3->Height));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox2MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
gbMDown=true;
grtLTRB.Left=X;
grtLTRB.Top=Y;
grtLTRB.Right=X;
grtLTRB.Bottom=Y;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox2MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
if(gbMDown)
{
if(X<0) X=0;
if(X>PaintBox2->Width) X=PaintBox2->Width;
if(Y<0) Y=0;
if(Y>PaintBox2->Height) Y=PaintBox2->Height;
PaintBox2->Canvas->CopyMode=cmSrcCopy;
PaintBox2->Canvas->CopyRect(grtLTRB, Image1->Canvas, grtLTRB);
grtLTRB.Right=X;
grtLTRB.Bottom=Y;
PaintBox2->Canvas->Brush->Style=bsClear;
PaintBox2->Canvas->Pen->Style=psDot;
PaintBox2->Canvas->Pen->Color=clBlack;
PaintBox2->Canvas->Rectangle(grtLTRB);
}
Application->ProcessMessages();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox2MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
gbMDown=false;
PaintBox2->Canvas->CopyRect(Rect(0, 0, PaintBox2->Width, PaintBox2->Height),
Image1->Canvas, Rect(0, 0, Image1->Width, Image1->Height));
Image3->Canvas->FillRect(Rect(0, 0, Image3->Width, Image3->Height));
Image3->Canvas->CopyRect(grtLTRB, Image1->Canvas, grtLTRB);
Label2->Caption="砆篒跋办: Rect("+IntToStr(grtLTRB.Left)+", "+
IntToStr(grtLTRB.Top)+", "+IntToStr(grtLTRB.Right)+", "+
IntToStr(grtLTRB.Bottom)+")";
}
//---------------------------------------------------------------------------
Top




