Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
i use this code
C#
private void button12_Click(object sender, EventArgs e)
{
    Bitmap bm = new Bitmap(pictureBox1.Image);
   Image<Gray, byte> img = new Image<Gray, byte>(bm);
    double x = 20;
    img.Rotate(x, new Gray(255));
    pictureBox9.Image = img.ToBitmap();

}

for image rotation
but it doesn't work ,
why????
Posted
Updated 9-Jan-12 10:41am
v3
Comments
Sergey Alexandrovich Kryukov 9-Jan-12 0:25am    
First of all, it won't even compile. :-) Please format your code properly.
--SA
elgammal 9-Jan-12 16:37pm    
Iam so sorry for this error ,
i don't how it is copied with this shape
this my actual code

private void button12_Click(object sender, EventArgs e)
{
Bitmap bm = new Bitmap(pictureBox1.Image);
Image<gray,byte> img = new Image<gray,byte>(bm);
double x = 20;
img.Rotate(x, new Gray(255));
pictureBox9.Image = img.ToBitmap();
}

follow this link: http://www.emgu.com/wiki/files/1.4.0.0/html/ae9c1603-5135-1a2f-bd46-1dd736d4d7a8.htm[^]

You will see the Rotate method also has an argument called crop, set this argument false and all information of your image will be preserved.

I think your code should be changed into:
C#
img = img.Rotate(x, new Gray(255),false);

Hope this will help you!
 
Share this answer
 
You may have to try this:
Image<Gray,Byte> imgOut= img.Rotate(x, new Gray(255));
pictureBox9.Image= imgOut.ToBitmap();

I did not compile, even though i have emgucv on my machine, but I looked into their libray. I believe you should call like I said above.

see their implementation:
public Image<TColor, TDepth> WarpAffine<TMapDepth>(Matrix<TMapDepth> mapMatrix, int width, int height, INTER interpolationType, WARP warpType, TColor backgroundColor) where TMapDepth: new()
{
Image<TColor, TDepth> image = new Image<TColor, TDepth>(width, height);
//this call externs c function
CvInvoke.cvWarpAffine(base.Ptr, image.Ptr, mapMatrix.Ptr, (int) (interpolationType | ((INTER) ((int) warpType))), backgroundColor.MCvScalar);
return image;
}
 
Share this answer
 
Comments
elgammal 10-Jan-12 9:44am    
thank you for this help ,
i use this and it work properly
but it has small fault which is that ,Rotation cut the image corners

i firstly use this method for image rotation:

private Bitmap rotateImage(Bitmap b, float angle)
{
//create a new empty bitmap to hold rotated image
Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
//make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(returnBitmap);
//move rotation point to center of image
g.TranslateTransform((float)b.Width/2, (float)b.Height / 2);
//rotate
g.RotateTransform(angle);
//move image back
g.TranslateTransform(-(float)b.Width/2,-(float)b.Height / 2);
//draw passed in image onto graphics object
g.DrawImage(b, new Point(0, 0));
return returnBitmap;
}

but it also cut image corners ,

i want some way not to cut image corners in EmguCV rotation ...
Well, in case of "it doesn't work".
The problem is not that complected.

change this line
img.Rotate(x, new Gray(255));

to
img = img.Rotate(x, new Gray(255));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900