2009-03-18 16 views
6

मुझे बिटमैप छवियों को उनके 4 कोने पॉइंट्स के साथ एक स्थान से दूसरे स्थान पर ले जाने की आवश्यकता है।4-पॉइंट ट्रांसफॉर्म छवियां

कोई भी कोड जो विंडोज, सी #/वीबी.नेट पर चलाया जा सकता है, यहां तक ​​कि Paint.NET या Photoshop जैसे स्क्रिप्ट योग्य प्रोग्रामों का उपयोग करने में भी मदद मिलेगी। जावा उन्नत इमेजिंग एपीआई आशावादी लगता है।

मैं एक स्क्रीनशॉट हेरफेर प्रणाली है, जो आपको इस तरह के प्रभावों को प्राप्त करने की अनुमति देता है के लिए इसकी आवश्यकता:

alt text http://www.wholetomato.com/images/tour/mondoPerspectiveTrans.gif

उत्तर

4

चेक बाहर ImageMagick से Perspective warping उदाहरण। यह ज्यादातर मुख्यधारा के प्लेटफार्मों के लिए उपलब्ध है।

1

आसान एक परिप्रेक्ष्य अनुकरण छवि हेरफेर का उपयोग कर बिगाड़ना से, आप इस्तेमाल कर सकते हैं OpenGL या DirectX (XNA) करने के लिए वास्तव में परिप्रेक्ष्य प्रदर्शन प्रदर्शन करते हैं।

बनावट मानचित्र के रूप में अपनी छवि के साथ एक साधारण ट्रैक्टर प्रस्तुत करें। अपने दृश्य को सेटअप करें, एक बफर को प्रस्तुत करें, और आपके पास अपनी छवि है।

अद्यतन यह पता चला है कि एक्सएनए एक हास्यास्पद पुस्तकालय है (गेम बनाने की दिशा में तैयार है और कुछ भी नहीं, यॉन)। प्रबंधित डायरेक्टएक्स को मस्तिष्क लोबोटॉमी की आवश्यकता होती है। ओपनजीएल का उपयोग करना आसान है, लेकिन छवि लोडिंग कोड की कमी है। यही कारण है कि हमें WPF के साथ छोड़ देता है:

alt text http://praeclarum.org/so/persp.png

छवि विरोधी उर्फ ​​मोड में WPF के लिए मजबूर द्वारा सुधार किया जा सकता है (क्यों ओह क्यों माइक्रोसॉफ्ट तुम इतनी अदूरदर्शी कर रहे हैं?), और एयरो ग्लास जो सैन्य बलों का इस्तेमाल नहीं द्वारा सभी स्क्रीनशॉट पर 1 पिक्सेल काली सीमा (या उस पिक्सेल सीमा को हटाकर)।

(इस कोड की लंबाई के लिए क्षमा करें, लेकिन WPF एक बातूनी एपीआई है।)

public partial class Window1 : Window { 
    const float ANGLE = 30; 
    const float WIDTH = 8; 
    public Window1() { 
     InitializeComponent(); 

     var group = new Model3DGroup(); 
     group.Children.Add(Create3DImage(@"C:\Users\fak\Pictures\so2.png")); 
     group.Children.Add(new AmbientLight(Colors.White)); 

     ModelVisual3D visual = new ModelVisual3D(); 
     visual.Content = group; 
     viewport.Children.Add(visual); 
    } 

    private GeometryModel3D Create3DImage(string imgFilename) { 
     var image = LoadImage(imgFilename); 

     var mesh = new MeshGeometry3D(); 
     var height = (WIDTH * image.PixelHeight)/image.PixelWidth; 
     var w2 = WIDTH/2.0; 
     var h2 = height/2.0; 
     mesh.Positions.Add(new Point3D(-w2, -h2, 0)); 
     mesh.Positions.Add(new Point3D(w2, -h2, 0)); 
     mesh.Positions.Add(new Point3D(w2, h2, 0)); 
     mesh.Positions.Add(new Point3D(-w2, h2, 0)); 
     mesh.TriangleIndices.Add(0); 
     mesh.TriangleIndices.Add(1); 
     mesh.TriangleIndices.Add(2); 
     mesh.TriangleIndices.Add(0); 
     mesh.TriangleIndices.Add(2); 
     mesh.TriangleIndices.Add(3); 
     mesh.TextureCoordinates.Add(new Point(0, 1)); // 0, 0 
     mesh.TextureCoordinates.Add(new Point(1, 1)); 
     mesh.TextureCoordinates.Add(new Point(1, 0)); 
     mesh.TextureCoordinates.Add(new Point(0, 0)); 

     var mat = new DiffuseMaterial(new ImageBrush(image)); 
     mat.AmbientColor = Colors.White; 

     var geometry = new GeometryModel3D(); 
     geometry.Geometry = mesh; 
     geometry.Material = mat; 
     geometry.BackMaterial = mat; 

     geometry.Transform = new RotateTransform3D(
      new AxisAngleRotation3D(new Vector3D(0,1,0), ANGLE), 
      new Point3D(0, 0, 0)); 

     return geometry; 
    } 

    public static BitmapSource LoadImage(string filename) { 
     return BitmapDecoder.Create(new Uri(filename, UriKind.RelativeOrAbsolute), 
      BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0]; 
    } 
} 

और आवश्यक XAML:

<Window x:Class="Persp.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Title="Perspective Window" Height="480" Width="640"> 
<Grid> 
    <Viewport3D x:Name="viewport"> 
     <Viewport3D.Resources> 
     </Viewport3D.Resources> 
     <Viewport3D.Camera> 
      <PerspectiveCamera x:Name="cam" 
        FarPlaneDistance="100" 
        LookDirection="0,0,-1" 
        UpDirection="0,1,0" 
        NearPlaneDistance="1" 
        Position="0,0,10" 
        FieldOfView="60" /> 
     </Viewport3D.Camera> 
    </Viewport3D> 
</Grid> 
</Window> 
+0

समस्या यह है कि आप 4 अंक को 3 डी रोटेशन में कैसे परिवर्तित करते हैं? –

2

कीवर्ड यहाँ homography है। Manolis Lourakis ने सी में एक जीपीएल 'होमोग्राफी कार्यान्वयन लिखा है जो here उपलब्ध है; हालांकि, यह बहुत आसानी से पोर्ट नहीं किया जा सका क्योंकि यह LAPACK जैसे कुछ बाहरी पुस्तकालयों पर निर्भर करता है।

2

अस्वीकरण: मैं Atalasoft

पर काम आप वाणिज्यिक जाने के लिए तैयार हैं, तो DotImage फोटो QuadrilateralWarpCommand के साथ ऐसा कर सकते हैं। नमूना सी # कोड

// Load an image. 
AtalaImage image = new AtalaImage("test-image.jpg"); 

// Prepare the warp positions. 
Point bottomLeft = new Point(100, image.Height - 80); 
Point topLeft = new Point(130, 45); 
Point topRight = new Point(image.Width - 60, 140); 
Point bottomRight = new Point(image.Width - 20, image.Height); 

// Warp the image. 
QuadrilateralWarpCommand cmd = new QuadrilateralWarpCommand(bottomLeft, 
    topLeft, topRight, bottomRight, InterpolationMode.BiLinear, Color.White); 
AtalaImage result = cmd.Apply(image).Image; 

http://www.atalasoft.com/products/dotimage

+0

क्या यह एक एफ़िन वार्प या परिप्रेक्ष्य वार है? –

+0

मुझे विश्वास नहीं है कि आप इसे एफ़िन वार्प (कम से कम 2 डी) के साथ प्राप्त नहीं कर सकते हैं, हम कई सामान्य एफ़िन रूपांतरणों का समर्थन करते हैं, और आप अपना 2 डी मैट्रिक्स बना सकते हैं। हम 3 डी ट्रांसफॉर्मेशन का समर्थन नहीं करते हैं (जो मुझे लगता है कि आपको मैट्रिक्स का उपयोग करके इस तरह के परिवर्तन करने की आवश्यकता होगी)। –

संबंधित मुद्दे