Rank: Member
Groups: Member
Joined: 4/27/2004(UTC) Posts: 40
|
I am trying to use the ProjectivePoints method of the BitmapClass oject in C# and I'm confused about the return value. I have a bitmap which is BitmapClass object, the method returns a Bitmap (interface?) object. When I try and access this object it tells me that its not instantiated. So I can't save it or do anything with it. The other problem I'm having is saving a bitmap out once I'm done with it. I want to write it to the Response.OutputStream - but it tells me that it doesnt implement the IStream interface - even thouhg the help file says you can do this. Any help would be most appreciated! Thanks! -- snippet -- Code:// use graphics mill to do a xform on the image
Aurigma.GraphicsMill.BitmapClass bmpGM = new Aurigma.GraphicsMill.BitmapClass();
MemoryStream memStream = new MemoryStream();
bmpCarpet.Save( memStream, System.Drawing.Imaging.ImageFormat.Jpeg );
bmpGM.LoadFromMemory(memStream.GetBuffer());
// xform
bmpGM.ProjectivePoints( 0,0,0,692,692,0,692,692,0,0,692,0,0,692,692,692,
0, urigma.GraphicsMill.InterpolationMode.InterpolationModeHighQuality,
Aurigma.GraphicsMill.FitMode.FitModeCircumscribed );
Edited by user Monday, December 24, 2007 5:56:37 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member
Groups: Member, Administration, Moderator Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
I am trying to use the ProjectivePoints method of the BitmapClass oject in C# and I'm confused about the return value. I have a bitmap which is BitmapClass object, the method returns a Bitmap (interface?) object. When I try and access this object it tells me that its not instantiated. So I can't save it or do anything with it.ProjectivePoints method returns null until you have set ApplyInPlace property to true value. Code:bmpGM.ApplyInPlace=true;
bmpGM.ProjectivePoints( 0,0,0,692,692,0,692,692,0,0,692,0,0,692,692,692,
0, urigma.GraphicsMill.InterpolationMode.InterpolationModeHighQuality,
Aurigma.GraphicsMill.FitMode.FitModeCircumscribed );
The other problem I'm having is saving a bitmap out once I'm done with it. I want to write it to the Response.OutputStream - but it tells me that it doesnt implement the IStream interface - even thouhg the help file says you can do this.Just use following code for sending image to output stream: Code:Response.BinaryWrite(objBitmap.SaveToMemory());
Edited by user Tuesday, December 15, 2009 10:20:50 AM(UTC)
| Reason: Not specified |
Best regards, Fedor Skvortsov
|
|
|
|
Rank: Member
Groups: Member
Joined: 4/27/2004(UTC) Posts: 40
|
Thanks for the prompt reply! Just an update: Code:Response.BinaryWrite((byte[])bmpGM.SaveToMemory());
You have to cast the BitmapClass object as a byte arrar or BinaryWrite complains. Is there an eary way to convert the BitmapClass to a System.Drawing.Bitmap? Thanks again! Edited by user Monday, December 24, 2007 5:57:28 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member
Groups: Member, Administration, Moderator Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
You have to cast the BitmapClass object as a byte arrar or BinaryWrite complains. Yes, exactly. Is there an eary way to convert the BitmapClass to a System.Drawing.Bitmap?View post |
Best regards, Fedor Skvortsov
|
|
|
|
Rank: Member
Groups: Member
Joined: 4/27/2004(UTC) Posts: 40
|
How do the points work? It says that the quadrangles need to be convex, but what does that mean exactly? I'm having a hard time describing the output that I want - I keep getting errors that points are incorrect. Is there a more complete description somewhere?
Thanks!
|
|
|
|
Rank: Advanced Member
Groups: Member, Administration, Moderator Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
1st quadrangle is convex. 2nd and 3rd quadrangles are not convex, as red point is inside 3 other points. However sometimes problems can be and with convex quadrangles as in 4th situation. Edited by user Monday, December 21, 2009 3:20:17 AM(UTC)
| Reason: Not specified Fedor attached the following image(s): |
Best regards, Fedor Skvortsov
|
|
|
|
Rank: Member
Groups: Member
Joined: 4/27/2004(UTC) Posts: 40
|
Thanks again.
How does the library determine where the point of view is? Cetrain values seem to make the top closer, while other make the bottom closer - same for left and right.
B
|
|
|
|
Rank: Advanced Member
Groups: Member, Administration, Moderator Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
In provided sample View postthe following code is used: Code:arrDestPointY(1) = (arrSrcPointY(1) + arrSrcPointY(2)) \ 2
arrDestPointY(2) = arrDestPointY(1)
arrDestPointY(3) = (arrSrcPointY(3) + arrSrcPointY(4)) \ 2
arrDestPointY(4) = arrDestPointY(3)
arrDestPointX(1) = (arrSrcPointX(1) + arrSrcPointX(4)) \ 2
arrDestPointX(4) = arrDestPointX(1)
arrDestPointX(2) = (arrSrcPointX(2) + arrSrcPointX(3)) \ 2
arrDestPointX(3) = arrDestPointX(2)
It means that it just averages the start and end coordinates of side lines. How does the library determine where the point of view is?It doesn't calculate the point of view explictiy, it just solves equation for creating projective matrix to transform source points do destination. Cetrain values seem to make the top closer, while other make the bottom closer - same for left and right. I also noticed it. I will discover it in details and post here my results in the nerarest time. |
Best regards, Fedor Skvortsov
|
|
|
|
Rank: Member
Groups: Member
Joined: 4/27/2004(UTC) Posts: 40
|
Thanks Fedor! You've been most helpful.
I look forward to the results of your expirements.
Brian
|
|
|
|
Rank: Member
Groups: Member
Joined: 4/27/2004(UTC) Posts: 40
|
I'm having trouble with following transformation:
source: (0,0)(1800,0)(0,1800)(1800,1800)
destination: (33,693)(439,683)(0,916)(1650,916)
This is a convex shape is it not? similar to the one the your drew in your example above (the first one, flipped upside down).
Thanks, Brian
|
|
|
|
Rank: Advanced Member
Groups: Member, Administration Joined: 8/2/2003(UTC) Posts: 876
Thanks: 2 times Was thanked: 27 time(s) in 27 post(s)
|
The shape formed with these points is self-crossing. To make sure, draw it with this code: Code:objGraphics.DrawLine 33, 693, 439, 683
objGraphics.DrawLine 439, 683, 0, 916
objGraphics.DrawLine 0, 916, 1650,916
objGraphics.DrawLine 1650,916, 33, 693
Self-crossing shapes are always non-convex (you can join vertices of the shape in such way that some points of your shape will be inside). To avoid self-crossing, try to swap points (for example third and fourth): Code:objGraphics.DrawLine 33, 693, 439, 683
objGraphics.DrawLine 439, 683, 1650,916
objGraphics.DrawLine 1650,916, 0, 916
objGraphics.DrawLine 0, 916, 33, 693
I hope this helps... Edited by user Monday, December 24, 2007 5:57:49 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member
Groups: Member, Administration Joined: 8/2/2003(UTC) Posts: 876
Thanks: 2 times Was thanked: 27 time(s) in 27 post(s)
|
By the way, I have a code sample, which should make using projective transform easier. The main problem in ProjectivePoints/ProjectiveMatrix is that there is a lot of parameters quite hard to manage. Using this sample you perform perspective distortion using single parameter (called perspectiveLevel here). All the parameters of ProjectivePoints are calculated automatically. It is written on VBScript for (classic ASP), but I think you will convert it to C# without any problems. Code:
<%
' Create new bitmap
Dim objBitmap
Set objBitmap = Server.CreateObject("GraphicsMill.Bitmap")
' Load the image
objBitmap.LoadFromFile "d:\[test files]\Pictures\andrew.jpg"
w = objBitmap.Width
h = objBitmap.Height
' Specify the perspective level here. The less value you specify,
' the more distortion you will get. Minimum value is 2 (trapezium is turned to
' triangle). Pass fractional values for fine tuning.
Dim perspectiveLevel
perspectiveLevel = 4.5
' Calculate coordinates of trapezium which
' specify shape of destination image
Dim a, b, c, d, scale
a = 0
b = h
c = h - h/perspectiveLevel + 1
d = h/perspectiveLevel - 1
' This ratio is required to save aspect of the image.
' To disable it, just specify scale to 1
scale = Abs((a-b)/(c-d))
' Apply projective transform. Source shape is original rectangle
' (last four points). Destination shape is a trapezium which we just
' calculated. Last parameter specifies the best quality (set 0 for worst
' quality, 1 for medium quality).
objBitmap.Transforms.ProjectivePoints 0, a, _
0, b, _
w/scale, c, _
w/scale, d, _
0, 0, _
0, h, _
w, h, _
w, 0, _
,2
' Display the result
objBitmap.SaveToStream Response
%>
The output image is the following: Edited by user Monday, December 21, 2009 3:20:44 AM(UTC)
| Reason: Not specified Andrew attached the following image(s):
|
|
|
|
Rank: Member
Groups: Member
Joined: 4/27/2004(UTC) Posts: 40
|
Thanks! I was able to get it working by rearranging the points that I used. Works like a charm now.
Brian Fluid Media
|
|
|
|
Rank: Member
Groups: Member
Joined: 4/27/2004(UTC) Posts: 40
|
I'm using projective points to mash a floor image into a room scene. Right now, I'm precalculating the points for each of my rooms, mostly by trial and error, and storing the related information in an xml file that gets loaded at run time. Would it be possible to calculate the necessary points by clicking on 4 corners in the image, providing the actual size of the room (say in feet) and the actual size the pre-transform floor image (also in feet)? For example: gmFloor, pre-transformation: gmBack (room scene): Final output: Would it be possible to generate the projective point programatically by clicking on 4 points in the room, give the actual length of each size and the actual size of the floor? I would still need to create a mask for the image, of course, but finding the points themselves has been a very slippery process so far. Thanks, Brian Edited by user Monday, December 21, 2009 3:21:33 AM(UTC)
| Reason: Not specified flluidmedia attached the following image(s):
|
|
|
|
Rank: Advanced Member
Groups: Member, Administration Joined: 8/2/2003(UTC) Posts: 876
Thanks: 2 times Was thanked: 27 time(s) in 27 post(s)
|
As far as I understand you want to make users clicking "anchor points"? I am not a guru in JavaScript and DHTML, but I think it is possible. After you get coordinates of points user specify, it is not a big problem to scale them to actual values (if you display resized image on client).
If you need to get these points once, you can create simple WinForms application which gets these points. It is much simplier (at least to me :) ). If you like I will send a sample.
|
|
|
|
Rank: Member
Groups: Member
Joined: 4/27/2004(UTC) Posts: 40
|
Andrew,
I was thinking more about it and, yes, a WinForm application would be much easier. It doesnt need to run on the web, just in house. Please send a sample, or post it here.
How would I ensure that the points are generated to take the perspective into account?
Thanks, Brian Fluid Media
|
|
|
|
Rank: Advanced Member
Groups: Member, Administration Joined: 8/2/2003(UTC) Posts: 876
Thanks: 2 times Was thanked: 27 time(s) in 27 post(s)
|
Here is a simple example on C#: http://www.aurigma.com/download/Samples/GraphicsMill_ProjectivePointsSample.zipIt just displays points you specify. Points are conjointed with lines so that you see when you set wrong order of traversal. As for more advanced ways to validate if points are correct, there are two ways: 1. Remember some math and check if the system of points is convex (it is always visible by eye though). However as ProjectivePoints fails with some convex systems (e.g. small trapezium on big image), it does not guaranty that it will work later. 2. Run ProjectivePoints and see if it return any error. It is simplier way, and besides it guaranties that these points will work with images of the same size you try. You can also View post. It is written on VB6 though.
|
|
|
|
Rank: Member
Groups: Member
Joined: 4/27/2004(UTC) Posts: 40
|
Thanks Andrew. I will have a look at that - I appreciate all the effort that you put into supporting your product.
Brian FluidMedia
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.