View Full Version : How Can I Draw something by mouse
June 28, 2004, 18:12:29
Thank you for you Help before !!
Everything work fine , I want to add some drawing function by mouse on the live picture, How can I detect the mouse action in listener ???
June 29, 2004, 08:08:38
the mouse events like mouse move are handled by the window in that the live video is displayed. You did this already in your CVisionView class in your project.
To detect the mouse events in your CListener class, you should add public methods to the CListener class, that are called from extern (CVisionView or CVisionDoc) when a mouse event occurs.
The easiest way is to implement a public method in your CVisionDoc(). Name it "MouseLButtonUp" and pass the point parameter to this function. Call this function from your CVisionView in the mouse event handler:
void CVisionView::OnLButtonUp(UINT nFlags, CPoint point)
GetDocument()->MouseLButtonUp( nFlags, point);
In the CVisionDoc class the method looks like follows:
void CVisionDoc::MouseLButtonUp(UINT nFlags, CPoint point)
m_cListener.MouseLButtonUp( nFlags, point);
With this the mouse event is directed to the CListener class and can be handled there. Implement the mouse move and mouse button down in the same way.
July 3, 2004, 18:22:41
How can I Change the drawing in the live video if i have some mouse action ??
Can you send me a sample in my project ??
July 5, 2004, 08:21:20
I have redesigned you project, so it is able to handle two cameras (there are two camera frames on your form view).
The mouse events are recieved in the CVisionView class. From there, the events are forwarded to the
CVision document. The CVision document knows, how many cameras are currently running and forwards
the mouse events to all listener objects. The listener objects know the rectangle,where the live
video of the regarding camera is displayed in. So the listeners are able to decide, whether the
must handle the mouse or not. I inserted displaying of the mouse coordinates on the regarded live
video. Please remark, that the mouse coordinates do not point to an absolute pixel on the live
video, because the display image has not the same size as the video image.
I have send the project source codes to your private email account.
July 5, 2004, 19:26:03
Thanks for Help !! Checking !!
July 7, 2004, 14:50:59
Please Send again the Zip file , I have some problem to open it !! Thanks !!
July 7, 2004, 14:56:34
Done. A little bit smaller than before, without Debug and Release directories.
July 7, 2004, 18:55:52
Thank you for your great help !!
In the live picture , I want to use the mouse to select the area , . if I select any pixel in the live picture then I move the mouse that will show a Rect, that Rect. will draw a New Rect from the selected pixel to current X,Y & erase the old Rect. after the secound pixel selected , the drawing Rect. No change & base on that Rect. to capture & save the live picture of that selected area for later use .
If the pointer is not in the actual pixel , How can I draw the Rect. in the live picture by mouse & How can I know the size of that selected area ??
please help !!!
July 8, 2004, 10:19:52
These are some simple C++ questions. You know the size of the live video image and the size of the bitmap, where the live video is displayed in. The mouse coordinates refer to the pixels on the bitmap, not on the live video. Therefore the mouse coordinates must be transformed to coordinates on the live video image. This is done by using the size relations between widths and heights from the live video to the bitmap.
First of all, you transform the mouse coordinates to a position on the bitmap:
void CListener::OnMouseMove(UINT nFlags, CPoint point)
// Check whether the mouse is over our rectangle. If so, display the mouse
if( point.x >= m_cCameraRect.left && point.x <= m_cCameraRect.right )
if( point.y >= m_cCameraRect.top && point.y <= m_cCameraRect.bottom )
m_cMousePosition.x = point.x - m_cCameraRect.left;
m_cMousePosition.y = point.y - m_cCameraRect.top;
In this CListener class is m_cCameraRect the rectangle that specifies the size of the bitmap in which the live video is displayed resized in. The position in is used to draw the rectangle, because it corresponds directly to the mouse pointer on the screen. Add m_cMousePosition as CPoint member
to the CListener class.
To transform the mouse position from the bitmap to the live video, you need the side relations from the bitmap to the live video. You need two factors and a little bit mathematics:
fWidthFactor = m_cCameraRect.Width / pInf->biWidth;
fHeightFactor = m_cCameraRect.Height / pInf->biHeight;
cImagePos.x = (int)( (float) m_cMousePosition.x * fWidthFactor;
cImagePos.y = (int)( (float) m_cMousePosition.y * fHeightFactor;
( I did not test this code, so may be the “*” should be exchanged by a “/”.) The coordinates in cImagePos represent the transformed pixel position on the live video.
You may save the video image width and height ( pInf->biWidth, pInf->biHeight ) as class members in CListener, so you have any time access to them.
I think, now it is easy for you to implement the drawings and specify the region of interest on your live video.
July 18, 2004, 19:37:09
can I use a simple way as "pBuffer->save(filemname) " to save the select image (part of live image) in BMP file ??
July 19, 2004, 07:09:10
pBuffer->save can only save the complete image. Cropping is not possible. The jpegdll is able to do so. The installation contains C++ samples, that crop a part of an image buffer and save them as jpeg file.
July 20, 2004, 19:05:54
Hi Thank your files
I have some problem in the follow ,
IF I type the no. in "//y lower right source rectangle coordinate." the picture is great perfect , but I try to type as follow , the picture as attached .
I try to change it to width() >> it's work perfect picture
i do something wrong ??
int iError = CropToJPEG("test.jpg", 80,
m_cRegionOfInterest.Width(), // JPEG image width.
m_cRegionOfInterest.Height(), // JPEG image height.
m_cRegionOfInterest.left, // x upper left source rectangle coordinate.
m_cRegionOfInterest.top, // y upper left source rectangle coordinate.
m_cRegionOfInterest.left+m_cRegionOfInterest.Width (),// x lower right source rectangle coordinate.
m_cRegionOfInterest.top+m_cRegionOfInterest.Height (),// y lower right source rectangle coordinate.
July 20, 2004, 19:11:02
I'm also try m_cRegionOfInterest.bottom / ....
seem only the y lower right will call the problem ....:confused: :confused: :confused: :confused:
July 22, 2004, 07:30:46
Seems there is a problem by running through the lines and addresse the column in the next line. Is the error in the jpegdll? Is the sinktype set to RGB24?
July 22, 2004, 17:26:44
Sink Type >> RGB24
yes Error in Jpegdll
I wll senda copy to you Please Help to check , what the probm come from !!
July 27, 2004, 12:26:15
when the X size of the picture cannot div by 4 the problem happen !!
Powered by vBulletin® Version 4.2.3 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.