小编Nic*_*nar的帖子

在类中使用OpenGL glutDisplayFunc

我已经创建了一个C++类(myPixmap)来封装OpenGL GLUT工具包执行的工作.display()该类的成员函数包含设置GLUT所需的大部分代码.


void myPixmap::display()
{
    // open an OpenGL window if it hasn't already been opened
    if (!openedWindow)
    {
        // command-line arguments to appease glut
        char *argv[] = {"myPixmap"};
        int argc = 1;
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize(640, 480);
        glutInitWindowPosition(30, 30);
        glutCreateWindow("Experiment");
        glutDisplayFunc(draw);
        glClearColor(0.9f, 0.9f, 0.9f, 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
        glutMainLoop();

        openedWindow = true;
    }  
}
Run Code Online (Sandbox Code Playgroud)

传递给的显示函数glutDisplayFunc()是该类的另一个成员函数:


void myPixmap::draw(void)
{
    glDrawPixels( m,n,GL_RGB,GL_UNSIGNED_BYTE, pixel );
}
Run Code Online (Sandbox Code Playgroud)

但是,Mac OS X 10.6.4上的gcc 4.2.1拒绝编译此代码,声称:

argument of type 'void (myPixmap::)()' …

c++ opengl compiler-errors class

27
推荐指数
1
解决办法
2万
查看次数

使用CUDA以非线性最小二乘方式求解方程组

使用CUDA,我想用非线性最小二乘求解器求解一个方程组.这些方法在一本优秀的小册子中讨论,可以在这里下载.

我的问题中的雅可比矩阵是稀疏的,下三角形.是否有可以使用这些方法的CUDA库,或者我是否必须自己从小册子中编写这些方法?

高斯 - 牛顿非线性最小二乘求解器,Levenberg-Marquardt或Powell的方法求解器是否可用于CUDA库(免费或非免费)?

cuda gpu linear-algebra mathematical-optimization hessian-matrix

10
推荐指数
1
解决办法
6625
查看次数

自动分离已经相乘的两个图像

我正在寻找一种算法或C++/Matlab库,可用于将两个图像相乘.下面给出了该问题的可视示例.

图像1可以是任何东西(例如相对复杂的场景).图像2非常简单,可以在数学上生成.图像2总是具有相似的形态(即下降趋势).通过将图像1乘以图像2(使用逐点乘法),我们得到变换后的图像.

给出转换后的图像,我想估计图像1或图像2.是否有算法可以做到这一点?

这是Matlab代码和图像:

load('trans.mat');
imageA = imread('room.jpg');
imageB = abs(response);  % loaded from MAT file

[m,n] = size(imageA);
image1 = rgb2gray( imresize(im2double(imageA), [m n]) );
image2 = imresize(im2double(imageB), [m n]);

figure; imagesc(image1); colormap gray; title('Image 1 of Room')
colorbar

figure; imagesc(image2); colormap gray; title('Image 2 of Response')
colorbar

% This is image1 and image2 multiplied together (point-by-point)
trans = image1 .* image2;
figure; imagesc(trans); colormap gray; title('Transformed Image')
colorbar
Run Code Online (Sandbox Code Playgroud)

图片1 图2 转化后的形象

UPDATE

有很多方法可以解决这个问题.以下是我的实验结果.感谢所有回答我问题的人!

1.图像的低通滤波

如duskwuff所述,采用变换图像的低通滤波器返回图像2的近似值.在这种情况下,低通滤波器是高斯滤波器.您可以看到可以使用低通滤波器识别图像中的乘法噪声.

原始图像 高斯低通滤波图像

2.同态过滤

正如EitenT所建议的,我研究了同态滤波.知道了这种类型的图像过滤的名称,我设法找到了一些我认为在解决类似问题时有用的参考文献.

  1. SP …

c++ matlab image image-processing

7
推荐指数
2
解决办法
680
查看次数

使用fft2在Matlab中对两个图像进行线性卷积

我想拍摄两张图像并使用2D FFT在Matlab中将它们一起卷积,而无需使用该conv2函数.但是,我不确定如何正确填充矩阵并为卷积做好准备.

数学运算如下:

A*B = C.

在上面,*是卷积运算符(维基百科链接).

以下Matlab程序显示了填充和不填充矩阵之间的区别.我怀疑不填充矩阵导致循环卷积,但我想执行线性卷积而没有混叠.

如果我填充两个矩阵,那么如何截断卷积的输出以使CAB的大小相同?

A = rgb2gray(im2double(imread('1.png'))); % input A
B = rgb2gray(im2double(imread('2.png'))); % kernel B

figure;
imagesc(A); colormap gray;
title ('A')

figure;
imagesc(B); colormap gray;
title ('B')

[m,n] = size(A);
mm = 2*m - 1;
nn = 2*n - 1;

C = (ifft2(fft2(A,mm,nn).* fft2(B,mm,nn)));

figure;
imagesc(C); colormap gray;
title ('C with padding')

C0 = (ifft2(fft2(A).* fft2(B)));

figure;
imagesc(C0); colormap gray; …
Run Code Online (Sandbox Code Playgroud)

matlab image-processing convolution

7
推荐指数
1
解决办法
1万
查看次数

优化以查找复数作为输入

我想知道是否有一个C/C++库或Matlab代码技术来使用最小化求解器来确定实数和复数.这是一个代码片段,显示了我想要做的事情.例如,假设我知道Utilde,但不是xU变量.我想使用optimization(fminsearch)来确定xU给定Utilde.请注意,这Utilde是一个复数.

x = 1.5;
U = 50 + 1i*25;
x0 = [1 20];  % starting values
Utilde = U * (1 / exp(2 * x)) * exp( 1i * 2 * x);
xout = fminsearch(@(v)optim(v, Utilde), x0);

function diff = optim(v, Utilde)
x = v(1);
U = v(2);
diff =  abs( -(Utilde/U) + (1 / exp(2 * x)) * exp( 1i * 2 * …
Run Code Online (Sandbox Code Playgroud)

c c++ matlab mathematical-optimization numerical-methods

6
推荐指数
1
解决办法
1273
查看次数

用于arm-linux-gcc的C/C++目标的简单makefile

我想使用arm-linux-gcc编译器套件[arm-linux-gcc(Buildroot 2011.08)4.3.6]交叉编译ARM架构的简单程序.我试图使用一个简单的makefile来编译C代码,另一个简单的makefile用于编译C++代码.例如,我的C代码生成文件在下面重现,但它不会创建一个ELF二进制文件,以便在我的嵌入式系统上运行.主机系统是x64 GNU Linux.

这是我为C程序编写的非常简单的makefile的列表:

CC=arm-linux-gcc
CFLAGS=-Wall
main: test.o 

clean:
    rm -f test test.o 
Run Code Online (Sandbox Code Playgroud)

上面复制的makefile只创建一个扩展名为.o的目标文件,而不创建ELF二进制文件.

我已经用Google搜索了一个很好的解决方案,但我似乎找不到一个显示C和C++程序的交叉编译ARM makefile的网页.也许这篇文章的答案可以显示这样的例子.

linux gcc arm cross-compiling gnu-make

5
推荐指数
2
解决办法
2万
查看次数

Segfault由于C文件中的一行代码而发生,并且整个程序不运行

我已经创建了一个C程序来写入嵌入式ARM系统上的串行端口(/ dev/ttyS0).在嵌入式ARM系统上运行的内核是Linux 3.0.4版,使用与下面列出的相同的交叉编译器构建.

我的交叉编译器是arm-linux-gcc(Buildroot 2011.08)4.3.6,在Ubuntu x86_64主机(3.0.0-14-generic#23-Ubuntu SMP)上运行.我已经使用stty实用程序从命令行设置串行端口.

神奇的是,如果存在单行代码,程序似乎将拒绝在嵌入式ARM系统上运行.如果删除该行,程序将运行.

这是一个完整的代码列表,复制问题:

编辑:我现在关闭错误文件,如下面的评论中所示.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <termios.h>

int test();
void run_experiment();

int main()
{
    run_experiment();
return 0;
}

void run_experiment()
{
    printf("Starting program\n");
    test();
} 

int test()
{
    int fd;
    int ret;

    fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY);
    printf("fd = %u\n", fd); 
    if (fd < 0)
    {
        close(fd);
        return 0;
    }

    fcntl(fd, F_SETFL, 0);

    printf("Now writing to …
Run Code Online (Sandbox Code Playgroud)

c file-io arm serial-port segmentation-fault

5
推荐指数
1
解决办法
2870
查看次数

使用Cmake进行混合语言C++,C和Fortran编译

使用g++,gccgfortran在GNU/Linux,我写了一个简单的脚本来编译和链接在一起的一些写在C++,C和Fortran源代码文件.以下是脚本的完整内容.此脚本已经过测试,效果很好.

g++ -c test-Q.cpp -I./boost/boost_1_52_0/ -g
 gcc -c paul2.c -g
 gcc -c paul2_L1.c -g
 gcc -c paul6.c -g
 gcc -c paul6_L1.c -g 
 gcc -c fit_slope.c -g
 gfortran -c getqpf.F -g
 g++ -o test-Q test-Q.o paul2.o paul2_L1.o paul6.o paul6_L1.o fit_slope.o getqpf.o -g -lgfortran
Run Code Online (Sandbox Code Playgroud)

为了使这更加跨平台,我想使用Cmake重新编写脚本.我如何处理混合语言编译?

下面列出的以下测试脚本不起作用,只会选择性地编译一些文件.

是否有另一个跨平台构建过程可能更适合这种类型的编译?

cmake_minimum_required (VERSION 2.6)
project (q-test)

include_directories(/media/RESEARCH/SAS2-version2/test-Q/boost/boost_1_52_0)

add_executable( q-test
test-Q.cpp
paul2.c
paul2_L1.c 
paul6.c 
paul6_L1.c 
fit_slope.c
getqpf.F
) # end
Run Code Online (Sandbox Code Playgroud)

gcc g++ cmake gfortran

4
推荐指数
1
解决办法
2655
查看次数

确定可以计入素数的下一个最高数字{2,3,5,7}

我想写一个函数,给出一个无符号整数作为输入参数,并返回可以计入素数{2,3,5,7}的下一个最高数字.这是一段简短的代码片段,展示了我想要做的事情.

unsigned int getHigherNumber(unsigned int x)
{
    // obtain the next highest number that can be factored into
    // prime numbers (2, 3, 5, and 7)
    if (~(x % 2 || x % 3 || x % 5 || x % 7))
        return  x;
    else
    {
         // ???
    }  
} // end
Run Code Online (Sandbox Code Playgroud)

此函数的目的是找到应填充数组的零的数量,以确保FFTW(链接)等算法能够以有效的方式运行.给定的链接讨论了该算法对于可以被分解为小素数的长度的输入是最优的.

如对该问题的评论中所建议的,如果FFTW算法是最优的,则看起来仅允许形式为2 ^ a*3 ^ b*5 ^ c*7 ^ d的数字.

c++ modulus

3
推荐指数
1
解决办法
546
查看次数

创建数组时Fortran中出现意外的数据声明错误

我编写了一个简单的测试程序来演示在编译一些Fortran代码时我收到的数据声明错误.编译错误发生在我试图创建任意大小的数组的行上.在C代码中,我相信这可以用一个简单malloc的方法完成,但这种方法在Fortran中可能没用.

这里出了什么问题,我该如何解决?我正在使用gfortran编译器GNU/Linux,所以我认为可以使用所有支持的语言功能.

这是我的测试程序:

program test
implicit none
    integer num1, num2

    print *, 'Starting...'
    num1 = 10
    num2 = 11
    call sub(num1, num2)
    print *, 'Done.'

end program



subroutine sub(num1, num2)
    integer num1, num2
    integer num3

    num3 = num1 + num2 - 1
    integer A(num3)

    do i = 1,num3
        A(i) = i
    end do

    print *, 'Now printing out vector'

    do i = 1,num3
        print *, A(i)
    end do
end subroutine
Run Code Online (Sandbox Code Playgroud)

这是cmake用于编译我的简单测试程序的脚本:

cmake_minimum_required …
Run Code Online (Sandbox Code Playgroud)

fortran

3
推荐指数
1
解决办法
2万
查看次数