用c++获取图片上一个特定点的像素坐标

jty940529 2015-05-13 11:52:32
将一张灰度化二值化后的的一张黑色图片上的一个白色亮点坐标提取出来,存到txt文件中,用c++如何实现?很着急,谢谢大家了。
...全文
2331 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2017-04-06
  • 打赏
  • 举报
回复
没准你得画一个红(255,0,0)点。
赵4老师 2017-04-06
  • 打赏
  • 举报
回复
最起码,你得先在src里面画一个白点吧。
darnell_cheng 2017-04-06
  • 打赏
  • 举报
回复
引用 18 楼 zhao4zhong1 的回复:
实际调试运行试试看。 不要迷信书、考题、老师、回帖; 要迷信CPU、编译器、调试器、运行结果。 并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。 任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实!
我调试了下,可以运行但是没法cout坐标值
赵4老师 2017-04-06
  • 打赏
  • 举报
回复
实际调试运行试试看。 不要迷信书、考题、老师、回帖; 要迷信CPU、编译器、调试器、运行结果。 并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。 任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实!
darnell_cheng 2017-04-05
  • 打赏
  • 举报
回复
引用 15 楼 zhao4zhong1 的回复:
    Mat bw;
for (int y=0;y<bw.rows;y++) {
        for (int x=0;x<bw.cols;x++) {
            gray_value_at_y_x=bw.at<uchar>(y,x);
        }
    }
这样可以实现特定像素值的点的坐标提取么?

Mat src;
for (int col = 340; col < 350; col++)  {
	for (int row = 0; row < src.rows ; row++) 
		{
		if (src.at<Vec3b>(col,row)[0] > 250
           && src.at<Vec3b>(col,row)[1] < 10
		   && src.at<Vec3b>(col,row)[2] < 10) 
           cout << row << "," << col << endl;
         }
    }
darnell_cheng 2017-04-05
  • 打赏
  • 举报
回复
引用 15 楼 zhao4zhong1 的回复:
    Mat bw;
for (int y=0;y<bw.rows;y++) {
        for (int x=0;x<bw.cols;x++) {
            gray_value_at_y_x=bw.at<uchar>(y,x);
        }
    }
我的意思是如何将特定的像素值(假设为(0,0,255))的点的坐标得出
赵4老师 2017-04-05
  • 打赏
  • 举报
回复
    Mat bw;
for (int y=0;y<bw.rows;y++) {
        for (int x=0;x<bw.cols;x++) {
            gray_value_at_y_x=bw.at<uchar>(y,x);
        }
    }
darnell_cheng 2017-04-05
  • 打赏
  • 举报
回复
引用 10 楼 zhao4zhong1 的回复:
离了我这颗胡萝卜还真上不了席了!
#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;
}
请问,如果我是将视频读入,想对每一帧图像提取特定像素的坐标,我是将Mat类转换为string类么?
赵4老师 2015-05-20
  • 打赏
  • 举报
回复
颗→棵
赵4老师 2015-05-15
  • 打赏
  • 举报
回复
输出到文件,参考#1
赵4老师 2015-05-15
  • 打赏
  • 举报
回复
离了我这颗胡萝卜还真上不了席了!
#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;
}
jty940529 2015-05-15
  • 打赏
  • 举报
回复
[quote=引用 10 楼 zhao4zhong1 的回复:] 离了我这颗胡萝卜还真上不了席了!
#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 非常感谢您!
jty940529 2015-05-14
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
仅供参考:
#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;
}

就是这张图片

请问怎么读出这张黑色图片上的这个白色亮点的坐标?最后这部分的应该怎么改改?
707wk 2015-05-14
  • 打赏
  • 举报
回复
引用 7 楼 jty940529 的回复:
[quote=引用 6 楼 zxh707wk 的回复:] http://baike.baidu.com/view/1080380.htm
请问如果要获取的点是白色的,而图片底色是黑色的,这个具体应该怎么修改程序以实现[/quote]问老赵
jty940529 2015-05-14
  • 打赏
  • 举报
回复
引用 6 楼 zxh707wk 的回复:
http://baike.baidu.com/view/1080380.htm
请问如果要获取的点是白色的,而图片底色是黑色的,这个具体应该怎么修改程序以实现
707wk 2015-05-14
  • 打赏
  • 举报
回复
http://baike.baidu.com/view/1080380.htm
jty940529 2015-05-14
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
仅供参考:
#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;
}



请问这几条语句是什么意思,怎么提取出来白色亮点的坐标?
此后三年 2015-05-14
  • 打赏
  • 举报
回复
先取得鼠标点击显示图片的控件的坐标, 在把这个坐标按照图片的长宽换算出来即可 例如: 控件点击点坐标(100,100); 控件的宽高(600,800); 图片宽高(2400,3200); x = (100 / 600)* 2400; y = (100 / 800) * 3200;
fly_dragon_fly 2015-05-14
  • 打赏
  • 举报
回复
就存一个坐标 ? ofstream os("zz.txt"); os<<"x="<<x<<",y="<<y<<endl; os.close();
jty940529 2015-05-14
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
仅供参考:
#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;
}
真的谢谢您,请问我该如何确定我提出来的点的坐标就是这个白色的亮点呢
加载更多回复(1)

64,636

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧