关于位图方面的(这个就是从四铮图里,分别取其相对的平均值,完后组合成一副完整的位图数据,之后,把它处理,但是其中有些地方不懂,可以较详细的解释下吗?)有错误

酬勤-人间道 2016-11-01 09:13:13
void CSCOMMDlg::Bilinear_interpolation()
{
if (m_vecImageData.size() <= 0)
{
return;
}
m_vecBilinearImageData.clear();
m_vecBilinearImageData.resize(m_vecImageData.size() * 4);

std::vector<int> vectemp0;
std::vector<int> vectemp1;
std::vector<int> vectemp2;

vectemp0.resize(m_vecImageData.size());
vectemp1.resize(m_vecImageData.size());
vectemp2.resize(m_vecImageData.size());

//step0
for (int i = 0;i < vectemp0.size();i++)
{
int a0,a1,a2,a3;
int sum;

if (i < IMAGE_HEIGHT) //第一排
{
if (i % (IMAGE_HEIGHT - 1) == 0 && i != 0)//最末端
{
sum = m_vecImageData[i];
}
else
{
a0 = m_vecImageData[i];
a1 = m_vecImageData[i + 1];

sum = (a0 + a1)/2;
}
}
else
{
int nCol = i / IMAGE_HEIGHT;

if (i % ((nCol + 1) * IMAGE_HEIGHT - 1) == 0)//最末端
{
a0 = m_vecImageData[i - IMAGE_HEIGHT];
a1 = m_vecImageData[i];

sum = (a0 + a1)/2;
}
else
{
a0 = m_vecImageData[i - IMAGE_HEIGHT];
a1 = m_vecImageData[i - IMAGE_HEIGHT + 1];
a2 = m_vecImageData[i];
a3 = m_vecImageData[i + 1];

sum = (a0 + a1 + a2 + a3)/4;
}
}
vectemp0[i] = sum;
}

//step1
for (int i = 0;i < vectemp1.size();i++)
{
int a0,a1,a2,a3;
int sum;

if (i < IMAGE_HEIGHT) //第一排
{
if (i == 0)//最前端
{
sum = (m_vecImageData[0] + vectemp0[0]) / 2;
}
else
{
a0 = vectemp0[i - 1];
a1 = vectemp0[i];
a2 = m_vecImageData[i];
sum = (a0 + a1 + a2)/3;
}
}
else
{
int nCol = i / IMAGE_HEIGHT;

if (i % IMAGE_HEIGHT == 0)//最前端
{
a0 = m_vecImageData[i - IMAGE_HEIGHT];
a1 = m_vecImageData[i];
a2 = vectemp0[i];

sum = (a0 + a1 + a2)/3;
}
else
{
a0 = m_vecImageData[i - IMAGE_HEIGHT];
a1 = m_vecImageData[i];
a2 = vectemp0[i - 1];
a3 = vectemp0[i];

sum = (a0 + a1 + a2 + a3)/4;
}
}
vectemp1[i] = sum;
}
//step2
for (int i = 0;i < vectemp2.size();i++)
{
int a0,a1,a2,a3;
int sum;

if (i >= (IMAGE_WIDTH - 1) * IMAGE_HEIGHT)//最后排
{
if (i == IMAGE_WIDTH * IMAGE_HEIGHT - 1)//最后排末端
{
sum = vectemp1[i];
}
else
{
a0 = vectemp1[i];
a1 = vectemp1[i + 1];

sum = (a0 + a1) / 2;
}
}
else
{
int nCol = i / IMAGE_HEIGHT;

if (i % ((nCol + 1) * IMAGE_HEIGHT - 1) == 0)//最末端
{
a0 = vectemp1[i];
a1 = vectemp1[i + IMAGE_HEIGHT];

sum = (a0 + a1)/2;
}
else
{
a0 = vectemp1[i];
a1 = vectemp1[i + 1];
a2 = vectemp1[i + IMAGE_HEIGHT];
a3 = vectemp1[i + IMAGE_HEIGHT + 1];
sum = (a0 + a1 + a2 + a3)/4;
}
}
vectemp2[i] = sum;
}

for (int i = 0 ;i < vectemp0.size();i++)
{
m_vecBilinearImageData[i * 4 + 0] = vectemp1[i];
m_vecBilinearImageData[i * 4 + 1] = vectemp0[i];
m_vecBilinearImageData[i * 4 + 2] = m_vecImageData[i];
m_vecBilinearImageData[i * 4 + 3] = vectemp2[i];
}
}
...全文
495 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-11-01
  • 打赏
  • 举报
回复
Computer_Vision_Algorithms_and_Applications_SzeliskiBook_20100903_draft.pdf 代码功能归根结底不是别人帮自己看或讲解或注释出来的;而是被自己静下心来花足够长的时间和精力亲自动手单步或设断点或对执行到某步获得的中间结果显示或写到日志文件中一步一步分析出来的。 提醒:再牛×的老师也无法代替学生自己领悟和上厕所! 单步调试和设断点调试(VS IDE中编译连接通过以后,按F10或F11键单步执行,按Shift+F11退出当前函数;在某行按F9设断点后按F5执行停在该断点处。)是程序员必须掌握的技能之一。 用一个足够小的图比如8x8像素大小的图辅助调试你这段代码,在代码的每一步,将每个像素的当前RGB或GRAY值输出到一个日志文件中。 写日志参考:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
    #pragma warning(disable:4996)
    #include <windows.h>
    #include <io.h>
#else
    #include <unistd.h>
    #include <sys/time.h>
    #include <pthread.h>
    #define  CRITICAL_SECTION   pthread_mutex_t
    #define  _vsnprintf         vsnprintf
#endif
//Log{
#define MAXLOGSIZE 20000000
#define MAXLINSIZE 16000
#include <time.h>
#include <sys/timeb.h>
#include <stdarg.h>
char logfilename1[]="MyLog1.log";
char logfilename2[]="MyLog2.log";
static char logstr[MAXLINSIZE+1];
char datestr[16];
char timestr[16];
char mss[4];
CRITICAL_SECTION cs_log;
FILE *flog;
#ifdef _MSC_VER
void Lock(CRITICAL_SECTION *l) {
    EnterCriticalSection(l);
}
void Unlock(CRITICAL_SECTION *l) {
    LeaveCriticalSection(l);
}
#else
void Lock(CRITICAL_SECTION *l) {
    pthread_mutex_lock(l);
}
void Unlock(CRITICAL_SECTION *l) {
    pthread_mutex_unlock(l);
}
#endif
void LogV(const char *pszFmt,va_list argp) {
    struct tm *now;
    struct timeb tb;

    if (NULL==pszFmt||0==pszFmt[0]) return;
    _vsnprintf(logstr,MAXLINSIZE,pszFmt,argp);
    ftime(&tb);
    now=localtime(&tb.time);
    sprintf(datestr,"%04d-%02d-%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday);
    sprintf(timestr,"%02d:%02d:%02d",now->tm_hour     ,now->tm_min  ,now->tm_sec );
    sprintf(mss,"%03d",tb.millitm);
    printf("%s %s.%s %s",datestr,timestr,mss,logstr);
    flog=fopen(logfilename1,"a");
    if (NULL!=flog) {
        fprintf(flog,"%s %s.%s %s",datestr,timestr,mss,logstr);
        if (ftell(flog)>MAXLOGSIZE) {
            fclose(flog);
            if (rename(logfilename1,logfilename2)) {
                remove(logfilename2);
                rename(logfilename1,logfilename2);
            }
        } else {
            fclose(flog);
        }
    }
}
void Log(const char *pszFmt,...) {
    va_list argp;

    Lock(&cs_log);
    va_start(argp,pszFmt);
    LogV(pszFmt,argp);
    va_end(argp);
    Unlock(&cs_log);
}
//Log}
int main(int argc,char * argv[]) {
    int i;
#ifdef _MSC_VER
    InitializeCriticalSection(&cs_log);
#else
    pthread_mutex_init(&cs_log,NULL);
#endif
    for (i=0;i<10000;i++) {
        Log("This is a Log %04d from FILE:%s LINE:%d\n",i, __FILE__, __LINE__);
    }
#ifdef _MSC_VER
    DeleteCriticalSection(&cs_log);
#else
    pthread_mutex_destroy(&cs_log);
#endif
    return 0;
}
//1-79行添加到你带main的.c或.cpp的那个文件的最前面
//81-86行添加到你的main函数开头
//90-94行添加到你的main函数结束前
//在要写LOG的地方仿照第88行的写法写LOG到文件MyLog1.log中
酬勤-人间道 2016-11-01
  • 打赏
  • 举报
回复
感谢,学生受教了
我将带领大家来系统学习Windows的窗口编程,包括消息、窗口、GDI绘图、游戏开发等。本课程比较基础,非常适合初学者入门,读者可以边学习边实践。具体的章节目录和课程内容如下所示:---------------------------------------------Windows游戏编程系列之1:GUI界面编程及游戏入门实战1、Windows创建第一个窗口 WinMain入口函数 5进行Windows编程的调试手法 6窗口从哪里来? 7窗口编程的步骤 7窗口编程需要的主要结构 8窗口编程需要的主要API 92、Windows的窗口过程与消息机制 如何留住窗口? 121)Windows的消息与消息循环 142)消息处理函数与常用消息 17)Windows的窗口过程函数 19 3、GDI编程之设备上下文 1)GDI的通用编程框架 222)GDI的绘图步骤 253)GDI获取设备句柄 254、GDI编程之绘制几何图形 画点、线 28颜色COLORREF 29矩形 29画圆、饼图、弦图 305、GDI编程之自定义画笔画刷画笔简介 32画刷简介 33画笔案例 33画刷案例 346、GDI编程之绘制文字 DrawText函数 35TextOut 函数 (wingdi.h) 36CreateFont函数 37绘制文本案例 377、GDI编程之绘制位图 位图简介 381)在资源中添加位图资源 392)从资源中加载位图: LoadBitmap 393)创建一个与当前DC相匹配的DC(内存DC) 394)将bitmap放入匹配的DC中:SelectObject 405)成像(1:1 比例 ) 406)取出位图 407)释放位图 418)释放匹配的DC 41绘制位图案例 41   8、Windows鼠标键盘消息 一、键盘消息 421、键盘消息 422、消息参数: 423、消息的使用: 424、键盘消息的案例代码 43二、鼠标消息 441、基本鼠标消息 442、双击消息 443、滚轮消息 454、不响应双击消息 45 9、Windows定时器消息 定时器消息介绍 47创建定时器 47关闭定时器 47定时器消息案例代码 4810、GDI游戏之跳舞动画 11、GDI游戏之走路动画 12、GDI贪吃蛇游戏实战  

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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