[英]Image rotation in C with OpenCV
for the needs of a project I have to make a function that rotate an image in C with the OpenCV library. 为了满足项目的需要,我必须使用OpenCV库制作一个函数,以C语言旋转图像。 I know that this library has some function to do that but I can only use the library to load the picture and print it in a window. 我知道该库具有执行此操作的功能,但是我只能使用该库加载图片并将其打印在窗口中。 I already have some code but OpenCV throw me an error and I don't understand why. 我已经有一些代码,但是OpenCV抛出一个错误,我不明白为什么。 Here is the error message: http://pastebin.com/5Y8Wc1SF 这是错误消息: http : //pastebin.com/5Y8Wc1SF
Also here is the code of my functions: http://pastebin.com/w0AAeqyc 这也是我的功能代码: http : //pastebin.com/w0AAeqyc
Can somebody help me to resolve it please? 有人可以帮我解决吗?
Your trig function results are assigned to the wrong type 您的触发函数结果分配给错误的类型
int cosd = cos(angle);
int sind = sin(angle);
They need to be 他们需要
double cosd = cos(angle);
double sind = sin(angle);
or float
. 或float
。 But when that is corrected, you can be getting negative image dimensions from these statements: 但是,在纠正此问题之后,您可以从这些语句中获得负的图像尺寸:
int new_width = (int)((img->width) * cosd + (img->height) * sind);
int new_height = (int)((img->height) * cosd + (img->width) * sind);
But seeing as it is unclear what axis is being rotated, I can't offer a solution. 但是,由于不清楚旋转的轴是什么,我无法提供解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.