小编Jiv*_*son的帖子

优化的图像卷积算法

我正在用 C++实现图像卷积,我已经有了一个基于给定伪代码的简单的工作代码:

for each image row in input image:
   for each pixel in image row:

      set accumulator to zero

      for each kernel row in kernel:
         for each element in kernel row:

            if element position  corresponding* to pixel position then
               multiply element value  corresponding* to pixel value
               add result to accumulator
            endif

      set output image pixel to accumulator
Run Code Online (Sandbox Code Playgroud)

由于这可能是大图像和内核的一大瓶颈,我想知道是否有其他方法可以使事情更快?即使有额外的输入信息,如:稀疏图像或内核、已知内核等......

我知道这可以并行化,但在我的情况下这是不可行的。

c++ algorithm math image-processing convolution

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

澄清想要重新.C++ type_traits

似乎要测试常量,必须测试模板参数,但要测试rvalue-ness,必须测试实际参数.(这是使用VC++ 2012.)这段代码说明了我的意思:

#include <type_traits>
#include <string>
#include <iostream>

using namespace std;

template<class T>
void f(T& x) {
    cout << "f() is_const<T> and is_const<decltype<x)>" << endl;
    cout << is_const<T>::value << endl; // Prints 1 when arg is const
    cout << is_const<decltype(x)>::value << endl; // Prints 0 when arg is const
}

template<class T>
void g(T&& x) {
    cout << "g() is_const<T> and is_const<decltype<x)>" << endl;
    cout << is_const<T>::value << endl; // Prints 0 when arg is const
    cout << is_const<decltype(x)>::value << …
Run Code Online (Sandbox Code Playgroud)

c++ templates type-traits c++11

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

Lambda在c ++中内部这个

如果lambda函数ic C++是由functor实现的,为什么这不可能?

#include <iostream>

class A
{
public: 
    int a;  
    void f1(){ [](){std::cout << this << std::endl ;}();};
};

int main()
{
    A a;
    a.f1();
}
Run Code Online (Sandbox Code Playgroud)

我收到错误9:34: error: 'this' was not captured for this lambda function.如果我的理解是正确的,如果拉姆达为函数子类实现的,为什么它是不可能得到它单曲内部这个

编辑:函子类,而不是这个类A的实例

c++ lambda this c++11

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

使用std :: move初始化std :: unique_ptr

最近我看到了一些与此类似的C++代码

class MyClass {
    public:
    MyClass(std::unique_ptr< MyType > myValue)
        : _myValue(std::move(myValue)) {}

    std::unique_ptr< MyType > _myValue;
};
Run Code Online (Sandbox Code Playgroud)

这是初始化unique_ptr的正确方法吗?是不是显式std :: move不必要?

c++ c++11

0
推荐指数
1
解决办法
279
查看次数

多线程上的信号量和关键部分问题

我的多线程代码存在问题,希望有人可以帮助我.

我希望在控制台上打印所有文件和文件夹,从作为参数给出的文件夹开始.我使用此函数进行枚举:

void enumerate(char* path) {
    HANDLE hFind;
    WIN32_FIND_DATA data;

    char *fullpath = new char[strlen(path) - 1];
    strcpy(fullpath, path);
    fullpath[strlen(fullpath) - 1] = '\0';

    hFind = FindFirstFile(path, &data);
    do {
        if (hFind != INVALID_HANDLE_VALUE) {
            if (strcmp(data.cFileName, ".") != 0 && strcmp(data.cFileName, ".."))
            {
                EnterCriticalSection(&crit);
                queue.push(data.cFileName);
                LeaveCriticalSection(&crit);
                ReleaseSemaphore(semaphore, 1, NULL);
                if (data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
                {
                    strcat(fullpath, data.cFileName);
                    strcat(fullpath, "\\*");
                    enumerate(fullpath);
                }
            }
        }
    } while (FindNextFile(hFind, &data));
    FindClose(hFind);

    return;
}
Run Code Online (Sandbox Code Playgroud)

当我找到文件或文件夹时,我想将其添加到全局队列中,并让我的工作线程将其打印到控制台.我的工作线程功能是:

DWORD WINAPI print_queue(LPVOID param) {
    while (1) {
        WaitForSingleObject(semaphore, …
Run Code Online (Sandbox Code Playgroud)

c++ winapi multithreading semaphore critical-section

0
推荐指数
1
解决办法
108
查看次数