将一张灰度化二值化后的的一张黑色图片上的一个白色亮点坐标提取出来,存到txt文件中,用c++如何实现?很着急,谢谢大家了。
|
5分 |
就存一个坐标 ?
ofstream os(“zz.txt”);
os<<“x=”<<x<<“,y=”<<y<<endl;
os.close();
|
5分 |
先取得鼠标点击显示图片的控件的坐标, 在把这个坐标按照图片的长宽换算出来即可
例如:
控件点击点坐标(100,100);
控件的宽高(600,800);
图片宽高(2400,3200);
x = (100 / 600)* 2400;
y = (100 / 800) * 3200;
|
|
仅供参考:
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace std;
using namespace Gdiplus;
int main() {
GdiplusStartupInput gdiplusstartupinput;
ULONG_PTR gdiplustoken;
GdiplusStartup(&gdiplustoken, &gdiplusstartupinput, NULL);
wstring infilename(L"1.jpg");
string outfilename("color.txt");
Bitmap* bmp = new Bitmap(infilename.c_str());
UINT height = bmp->GetHeight();
UINT width = bmp->GetWidth();
cout << "width " << width << ", height " << height << endl;
Color color;
ofstream fout(outfilename.c_str());
for (UINT y = 0; y < height; y++)
for (UINT x = 0; x < width ; x++) {
bmp->GetPixel(x, y, &color);
fout << x << "," << y << ";"
<< (int)color.GetRed() << ","
<< (int)color.GetGreen() << ","
<< (int)color.GetBlue() << endl;
}
fout.close();
delete bmp;
GdiplusShutdown(gdiplustoken);
return 0;
}
|
|
真的谢谢您,请问我该如何确定我提出来的点的坐标就是这个白色的亮点呢
|
|
请问这几条语句是什么意思,怎么提取出来白色亮点的坐标?
|
|
http://baike.baidu.com/view/1080380.htm
|
|
请问如果要获取的点是白色的,而图片底色是黑色的,这个具体应该怎么修改程序以实现
|
|
问老赵
|
|
|
30分 |
离了我这颗胡萝卜还真上不了席了!
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace std;
using namespace Gdiplus;
int main() {
GdiplusStartupInput gdiplusstartupinput;
ULONG_PTR gdiplustoken;
GdiplusStartup(&gdiplustoken, &gdiplusstartupinput, NULL);
wstring infilename(L"1.jpg");
Bitmap* bmp = new Bitmap(infilename.c_str());
UINT height = bmp->GetHeight();
UINT width = bmp->GetWidth();
Color color;
for (UINT y = 0; y < height; y++)
for (UINT x = 0; x < width ; x++) {
bmp->GetPixel(x, y, &color);
if ((int)color.GetRed ()>200
&& (int)color.GetGreen()>200
&& (int)color.GetBlue ()>200) {
cout << x << "," << y << endl;
goto EXIT;
}
}
EXIT:
delete bmp;
GdiplusShutdown(gdiplustoken);
return 0;
}
|
|
输出到文件,参考#1
|
|
离了我这颗胡萝卜还真上不了席了!
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace std;
using namespace Gdiplus;
int main() {
GdiplusStartupInput gdiplusstartupinput;
ULONG_PTR gdiplustoken;
GdiplusStartup(&gdiplustoken, &gdiplusstartupinput, NULL);
wstring infilename(L"1.jpg");
Bitmap* bmp = new Bitmap(infilename.c_str());
UINT height = bmp->GetHeight();
UINT width = bmp->GetWidth();
Color color;
for (UINT y = 0; y < height; y++)
for (UINT x = 0; x < width ; x++) {
bmp->GetPixel(x, y, &color);
if ((int)color.GetRed ()>200
&& (int)color.GetGreen()>200
&& (int)color.GetBlue ()>200) {
cout << x << "," << y << endl;
goto EXIT;
}
}
EXIT:
delete bmp;
GdiplusShutdown(gdiplustoken);
return 0;
}
[/quot
非常感谢您!
|
|
颗→棵
|