小编Mum*_*wiz的帖子

在python中使用PIL模糊图像

我一直试图使用PIL模糊图像.

据我所知,我需要复制图像,然后从原始图片中将每个像素更改为周围像素的平均值.所以我没有走得太远,我正在使用python 3.3x

from PIL import Image 

img = Image.open("source")
im = Image.copy(img)
Run Code Online (Sandbox Code Playgroud)

我知道如何使用putpixe,并获取像素的数据,但我无法弄清楚如何获得周围像素的平均值.

在此先感谢您的帮助!

image pixel python-imaging-library python-3.x

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

找到最小和最大像素的值

我计算了灰度图像中像素的最小和最大像素值,如下所示:

smallest = numpy.amin(image)
biggest = numpy.amax(image)
Run Code Online (Sandbox Code Playgroud)

但这只适用于灰度.

如何为彩色图像(RGB)执行相同操作?

python arrays numpy image colors

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

如何使NetBeans将.cpp文件视为C++源代码?

在NetBeans中编程时,我下载了所有正确的编译器.C对我来说很好.

但是现在我开始使用C++,我意识到在打开一个带有扩展.cpp的新源文件C++时,NetBeans会转到C编译器,然后找不到包含<iostream>等等.

但是当使用扩展打开文件时,.c++NetBeans会转到正确的目录并确实识别C++相关的所有内容.有没有办法改变它,以便扩展.cpp也将转到正确的目录?谢谢!

c++ netbeans

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

在 MenuList 中 React-Select 自定义输入

我正在尝试使用 React-Select 选项创建自定义选择。我希望我的搜索不在控制框中,而是在菜单中。我试过这个:

import React from "react";
import Select, { components } from "react-select";
import { colourOptions, groupedOptions } from "./docs/data";


const MenuList = props => {
  return (
    <components.MenuList {...props}>
      <components.Input {...props} />;
      {props.selectProps.inputValue.length > 1 ? props.children : ""}
    </components.MenuList>
  );
};
export default () => (
  <Select
    defaultValue={colourOptions[1]}
    options={groupedOptions}
    components={{ MenuList }}
  />
);
Run Code Online (Sandbox Code Playgroud)

问题是我收到一条错误消息

Uncaught Invariant Violation: input is a void element tag and must neither have children nor use dangerouslySetInnerHTML
Run Code Online (Sandbox Code Playgroud)

我猜反应选择components.Input是在input标签内渲染另一个 …

reactjs react-select

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

swig - C++ 到 JavaScript

我正在尝试使用我的 cpp 文件中的 swig 构建一个简单的 javascript 模块。我运行了所有正确的命令,但似乎没有任何效果。\n这是我的.h文件

\n\n
#pragma once\n\nclass Die\n{\npublic:\n    Die();\n    Die(int a);\n    ~Die();\n    int foo(int a) ;\n    Die* getDie(int a);\n    int myVar;\n};\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的.cpp文件:

\n\n
 #include <iostream>\n#include "example.h"\nint Die::foo(int a) {\n\n    std::cout << "foo: running fact from simple_ex" <<std::endl;\n    return 1;\n}\n\nDie::Die(){}\nDie::Die(int a){myVar = a;}\nDie::~Die(){}\nDie* Die::getDie(int a) {\n    return new Die (a);\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的.i文件:

\n\n
%module example\n%{\n#include "example.h"\n%}\n%include "example.h"\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的binding.gyp文件:

\n\n
{\n  "targets": [\n    {\n      "target_name": "example",\n      "sources": ["example.cpp", "example_wrap.cxx" …
Run Code Online (Sandbox Code Playgroud)

javascript c++ swig v8 node.js

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

在使用中反应钩子道具

我已经开始使用react-hooks并且有一些我想了解的东西。我有这个useEffect钩子,我正在分离useEffect钩子,我想知道每个钩子何时运行。

function MyComp(props) {
    useEffect(
       () => {
         fetchSomeData(props.filters)
       },[props.filters]
     )
    return (
        <div>will show my data here</div>
     )
}
Run Code Online (Sandbox Code Playgroud)

此挂钩是否仅在props.filters更改后才运行?

还是我必须使用prevProps检查它是否已更改?

像这样:

function MyComp(props) {
   const prevProps = useRef(props);
   useEffect(
       () => {
           if (prevProps.filters !== props.filters) {            
              fetchSomeData(props.filters)
           }
       },[props.filters]
   )
   return (
     <div>will show my data here</div>
   )
}
Run Code Online (Sandbox Code Playgroud)

reactjs react-props react-hooks

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

将 void* 转换为 std::function

我有一个问题。我正在尝试将 void* 转换为 std::function 。这只是一个简单的例子,任何建议将不胜感激

#.h file
class Example {

public:

  Example();
  int foo(void* hi);

  int fooFunc(std::function<int(int, int)> const& arg, int x, int y) {
    foo(arg.target<void*>(), x, y);
    return 2;
  }

};


#.cpp file
Example::Example() {

  }

  int Example::foo(void * func, int x, int y)
  {
    //cast back to std::function
    func(x, y);
    std::cout << "running in foo: " << a << "\n";
    return a;
  }
Run Code Online (Sandbox Code Playgroud)

我尝试的每一次选角都不起作用。

我知道我可以在这个例子中发送一个std::function,但这是为了更大的事情,我正在研究一个例子以使其在这里工作。

,的全部含义void*是有时在这些情况下使用它,当您不知道您将收到什么时,然后将其转换为您需要的特定用法。

谢谢!

casting void-pointers c++11 std-function

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

重载operator =中的内存泄漏

我有这个矩阵的构造函数来分配内存

class Matrix 
{

public:
    int** matrix;
    int cols;
    int rows;
};
Matrix::Matrix(int row, int col)
{
    cols = col;
    rows = row;
    matrix = new int*[rows];
    int i;
    for (i = 0; i < rows; ++i)
    {
        matrix[i] = new int[cols];
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我想重载operator =,但我无法弄清楚如何编写函数并分配新内存,而不会导致内存泄漏或内存不足.

我要做的矩阵=在它上面,已经为它分配了内存,那么我可以删除内存并使另一个内存大小的新内存吗?

现在我在operator =上有这个

this->rows = other.rows;
this->cols = other.cols;

int i, j;
for (i = 0; i < this->rows; ++i)
{
    for (j = 0; j < this->cols; j++)
    {
        this->matrix[i][j] = other.matrix[i][j];
    } …
Run Code Online (Sandbox Code Playgroud)

c++ memory memory-leaks memory-management

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