小编use*_*624的帖子

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

如何在 mongoose/mongodb 查询子文档中使用 mapreduce?

我在 mongoose/mongodb 中实现了一个简单的消息系统,架构如下

var schema = new mongoose.Schema({
    user: {type:String, required:true},
    updated: {type:Date, default:new Date()},       
    msgs: [ {m:String, // message itself 
             d:Date,   // date of message
             s: String,  // message sender
             r:Boolean   // read or not
            } ],
});
Run Code Online (Sandbox Code Playgroud)

所有消息都存储在 msg 嵌套数组中,现在我想查询来自某个发件人的消息,例如,

{
  "_id" : ObjectId("52c7cbe6d72ecb07f9bbc148"),
  'user':'abc'
  "msgs" : [{
      "m" : "I want to meet you",
      "d" : new Date("4/1/2014 08:52:54"),
      "s" : "user1",
      "r" : false,
      "_id" : ObjectId("52c7cbe69d09f89025000005")
    }, {
      "m" : "I want to meet you", …
Run Code Online (Sandbox Code Playgroud)

mapreduce mongoose mongodb node.js

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

matplotlib无法在OS X中运行,错误"TKApplication同时实现"

我使用的是Mac OS X Yosemite 10.10.1,我已经安装了matplotlib pip install matplotlib.

我尝试了一个简单的应用程序如下.

import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()
Run Code Online (Sandbox Code Playgroud)

python应用程序运行并显示窗口,但没有任何图形.命令行刚给我一个错误说:

Class TKApplication is implemented in both /Users/xisizhe/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
 Class TKMenu is implemented in both /Users/xisizhe/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
Class TKContentView is implemented in both /Users/xisizhe/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one …
Run Code Online (Sandbox Code Playgroud)

python macos matplotlib

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

在图像中裁剪图像?

我正在使用skimage来裁剪给定图像中的矩形,现在我将(x1,y1,x2,y2)作为矩形坐标,然后我加载了图像

 image = skimage.io.imread(filename)
 cropped = image(x1,y1,x2,y2)
Run Code Online (Sandbox Code Playgroud)

然而,这是裁剪图像的错误方法,我将如何以正确的方式在skimage中进行

python image-processing scikit-image

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

如何在opencv python中更改图像照明

我在python opencv中读取图像,现在我需要将此图像上的照明更改为更暗或更亮,我应该使用哪种方法来启用此功能?

python opencv

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

在切换到 stomp-client 时使用 node-amqp 库进行身份验证失败,它可以工作

我正在使用node-amqp库连接到在线stomp服务,在我使用stomp-client之前,它连接非常成功,但它不支持自动故障检测和重新连接,所以我想切换到node-amqp 提供更强大的支持。

var amqp = require('amqp');
var option = { 
  host: 'host'
, port: 61618
, login: 'my username'
, password: 'my password'
};

var implOpts = {
      reconnect: true,
      reconnectBackoffStrategy: 'exponential',
      reconnectBackoffTime: 500
};

var connection  = amqp.createConnection(option,implOpts);
connection.addListener('ready', function(){
    console.log('ready connection ');

});

connection.on('error', function (error) {
    console.log('Connection error' ,error);

});

connection.on('close', function () {
    console.log('Connection close ');

});
Run Code Online (Sandbox Code Playgroud)

主机名、密码、用户名和端口正确并且在 stomp-client 库示例中工作。但是,通过使用上面的代码,我收到一条错误消息:连接错误 { message: '连接结束:可能是由于身份验证失败。' }。我查看了代码,没有发现我的身份验证或代码有任何问题。

这是 stomp-client 库中的工作代码。

var StompClient = …
Run Code Online (Sandbox Code Playgroud)

stomp amqp node.js node-amqp

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

如何在python中读取Mat v7.3文件?

我正在尝试阅读以下网站ufldl.stanford.edu/housenumbers中提供的mat文件,在文件train.tar.gz中,有一个名为digitStruct.mat的mat文件。

当我使用scipy.io读取mat文件时,它以消息“请为matlab v7.3文件使用hdf阅读器”提醒我。

原始的matlab文件提供如下

load digitStruct.mat
for i = 1:length(digitStruct)
    im = imread([digitStruct(i).name]);
    for j = 1:length(digitStruct(i).bbox)
        [height, width] = size(im);
        aa = max(digitStruct(i).bbox(j).top+1,1);
        bb = min(digitStruct(i).bbox(j).top+digitStruct(i).bbox(j).height, height);
        cc = max(digitStruct(i).bbox(j).left+1,1);
        dd = min(digitStruct(i).bbox(j).left+digitStruct(i).bbox(j).width, width);

        imshow(im(aa:bb, cc:dd, :));
        fprintf('%d\n',digitStruct(i).bbox(j).label );
        pause;
    end
end
Run Code Online (Sandbox Code Playgroud)

如上所示,mat文件具有键“ digitStruct”,并且在“ digitStruct”中可以找到键“ name”和“ bbox”,我使用h5py API读取了文件。

import h5py
f = h5py.File('train.mat')
print len( f['digitStruct']['name'] ), len(f['digitStruct']['bbox']   )
Run Code Online (Sandbox Code Playgroud)

我可以读取数组,但是当我遍历数组时,如何读取每个项目?

for i in f['digitStruct']['name']:
    print i # only print out the HDF5 ref
Run Code Online (Sandbox Code Playgroud)

python matlab hdf5 h5py mat

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

RuntimeError:针对API版本a编译的模块,但是这个版本的numpy在ubuntu中是9

我刚刚安装了theano,但是

import numpy
print numpy.version
Run Code Online (Sandbox Code Playgroud)

这是输出

Theano version 0.7.0.dev-30cc6380863b08a3a90ecbe083ddfb629a56161d
theano is installed in /home/sizhexi/theano/Theano/theano
NumPy version 1.8.2
NumPy is installed in /usr/lib/python2.7/dist-packages/numpy
Python version 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2]
nose version 1.3.1
RuntimeError: module compiled against API version a but this version of numpy is 9
terminate called after throwing an instance of 'std::runtime_error'
  what():  numpy failed to initialize
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)

怎么解决?

numpy theano

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

如何根据opencv中的深度颜色分割连接区域

我有一张照片 在此输入图像描述,我需要将图片分成8个块.

我试过这个阈值方法

img_gray = cv2.imread(input_file,cv2.IMREAD_GRAYSCALE)
ret,thresh = cv2.threshold(img_gray,254,255,cv2.THRESH_BINARY) =
kernel = np.array(cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3), (-1, -1)))
img_open = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)
cv2.imshow('abc',img_open)
ret1,thresh1 = cv2.threshold(img_open,254,255,cv2.THRESH_BINARY_INV) #
contours, hierarchy = cv2.findContours(thresh1, cv2.RETR_CCOMP ,cv2.CHAIN_APPROX_NONE)

for i in range(len(contours)):
    if len(contours[i]) > 20:
        x, y, w, h = cv2.boundingRect(contours[i])
        cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2)
        print (x, y),(x+w, y+h)
Run Code Online (Sandbox Code Playgroud)

在阈值之后
在此输入图像描述

最终的结果是连接在一起的一些块形成了一个大段,这不是我所希望的. 在此输入图像描述 在此输入图像描述 在此输入图像描述 任何其他方式来解决它

opencv image-processing computer-vision image-segmentation

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

如何将 bootstrap 或 tailwind css 名称解析为非 bootstrap 或非 tailwind css 名称

我制作了一个基于 bootstrap 和 tailwind 的 Web 应用程序,但是我不希望在浏览器工具中清晰地查看我的 Web 应用程序 UI。所以我想知道在公开发布Web应用程序之前是否可以将顺风CSS名称解析为随机名称?

bootstrap-4 tailwind-css

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