c# - 从特定点而不是中心旋转图像c#
问题描述
我有几张如下图所示的图像,我想将它们旋转几次以进行 OCR。每次10度。
我现在遇到的问题是我可以从中心旋转图像,但是黑色字母始终位于图像中的随机点。因此,虽然我可以再将它旋转 10 度,但它通常会脱离图像。
如何从字母当前所在的中心旋转下面的图像?
请记住,它的位置是随机的。
这是我目前用于旋转的代码
Bitmap rotatedImage = new Bitmap(bmp.Width, bmp.Height);
using (Graphics g = Graphics.FromImage(rotatedImage))
{
// Set the rotation point to the center in the matrix
g.TranslateTransform(bmp.Width / 2, bmp.Height / 2);
// Rotate
g.RotateTransform(angle);
// Restore rotation point in the matrix
g.TranslateTransform(-bmp.Width / 2, -bmp.Height / 2);
// Draw the image on the bitmap
g.DrawImage(bmp, new System.Drawing.Point(0, 0));
}
return rotatedImage;
这是我创建的用于查找字母第一个黑色像素位置的代码。
float limit = 0.1f;
int x = 0;
int y = 0;
bool done = false;
for (int i = 0; i < bmp.Width; i++)
{
if (done) break;
for (int j = 0; j < bmp.Height; j++)
{
if (done) break;
System.Drawing.Color c = bmp.GetPixel(i, j);
if (c.GetBrightness() < limit)
{
x = i; y = j; done = true;
}
}
}
但是,当我在旋转代码中使用该位置时,我只会得到一个空白的白色图像。
包含字母的图片
解决方案
推荐阅读
- performance - isPascal() 方法的时间复杂度是多少
- javascript - GraphQl 突变错误结果
- ruby-on-rails - 使用 Rails 和 mongoid 的 MongoDB 中的 UUID 字段
- python - API调用期间如何循环列表?
- javascript - 在 express 节点 js 中重新渲染 EJS 模板
- javascript - Webpack 如何需要 .node 文件(在 Vue Electron 中使用 WebChimera.js 包)
- networking - 将本地端口从 Raspbian 路由到另一台机器(端口隧道)
- arrays - 计算行元素的 DISTINCT 副本
- c - C程序不打印作为输入给出的字符串
- google-developers-console - 跳过 Google Play 开发者控制台中的发布