我还在学习C++,我到处都在阅读,我必须尽可能地使用const它(出于速度原因,我认为).
我经常写这样的getter方法:
const bool isReady() {
return ready;
}
Run Code Online (Sandbox Code Playgroud)
但我已经看到一些IDE以这种方式自动生成getter:
bool getReady() const {
return ready;
}
Run Code Online (Sandbox Code Playgroud)
但是,写代表,如果const在函数之后,我发现这个错误:
member function 'isReady' not viable: 'this' argument has type 'const VideoReader', but function is not marked const
Run Code Online (Sandbox Code Playgroud)
那么,编写const getter的更好方法是什么?我真的要关心吗?
我想在C++接口(cv命名空间)中使用k-means和OpenCV对图像进行分色,我得到了奇怪的结果.我需要它来减少一些噪音.这是我的代码:
#include "cv.h"
#include "highgui.h"
using namespace cv;
int main() {
Mat imageBGR, imageHSV, planeH, planeS, planeV;
imageBGR = imread("fruits.jpg");
imshow("original", imageBGR);
cv::Mat labels, data;
cv::Mat centers(8, 1, CV_32FC1);
imageBGR.convertTo(data, CV_32F);
cv::kmeans(data, 8, labels,
cv::TermCriteria(CV_TERMCRIT_ITER, 10, 1.0),
3, cv::KMEANS_PP_CENTERS, ¢ers);
imshow("posterized hue", data);
data.convertTo(data, CV_32FC3);
waitKey();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了一个奇怪的结果

第一张图片:原创
第二张图片:k-means之后.
有什么建议?
#include "cv.h"
#include "highgui.h"
#include <iostream>
using namespace cv;
using namespace std;
int main() {
Mat src;
src = imread("fruits.jpg");
imshow("original", src);
blur(src, src, Size(15,15));
imshow("blurred", …Run Code Online (Sandbox Code Playgroud) 我想从官方文档中应用"常规更新模式"来更新鼠标事件的svg路径(但可以是按钮或其他).
但路径只是添加而不是更新.我认为这就是为什么我没有正确使用enter和exit属性,但经过一些不同的试验,我无法让它工作.
这是一个jsfiddle.
我的js代码在这里:
var shapeCoords = [
[10, 10], [100, 10], [100, 100], [10, 100]
];
$(function() {
var container = $('#container');
// D3
console.log("D3: ", d3);
var svg = d3.select('#container')
.append('svg:svg')
.attr('height', 600)
.attr('width', 800);
var line = d3.svg.line()
.x(function(d) { return d[0]; })
.y(function(d) { return d[1]; })
.interpolate('linear');
function render() {
svg.data(shapeCoords)
.append('svg:path')
.attr('d', line(shapeCoords) + 'Z')
.style('stroke-width', 1)
.style('stroke', 'steelblue');
}
render();
var mouseIsDown = false;
container.on('mousedown …Run Code Online (Sandbox Code Playgroud) 这有点我没有python语法,我在读取.ini带插值的文件时遇到问题.
这是我的ini文件:
[DEFAULT]
home=$HOME
test_home=$home
[test]
test_1=$test_home/foo.csv
test_2=$test_home/bar.csv
Run Code Online (Sandbox Code Playgroud)
那些台词
from ConfigParser import SafeConfigParser
parser = SafeConfigParser()
parser.read('config.ini')
print parser.get('test', 'test_1')
Run Code Online (Sandbox Code Playgroud)
输出
$test_home/foo.csv
Run Code Online (Sandbox Code Playgroud)
虽然我在期待
/Users/nkint/foo.csv
Run Code Online (Sandbox Code Playgroud)
我认为$语法隐含在所谓的字符串插值中(参考手册):
除了核心功能之外,SafeConfigParser还支持插值.这意味着值可以包含引用同一节中其他值的格式字符串,或特殊DEFAULT节中的值.
但我错了.如何处理这种情况?
嗨,我想在表中不活动.即使我自己很容易破解并添加一个自定义css与我当前主题的非活动元素的颜色相同,我认为它可以由bootstrap本身处理.
有什么建议?
我想使用Opencv卡尔曼滤波器实现平滑一些噪声点.所以我试着为它编写一个简单的测试代码.
假设我有观察(一点).我接受新观察的每一帧,我称卡尔曼预测和卡尔曼正确.opencv卡尔曼滤波器正确后的状态是"跟随点",没关系.
然后,假设我有一个缺失的观察,我想要无论如何都要更新卡尔曼滤波器并预测新状态.这里我的代码失败了:如果我调用kalman.predict(),则值不再更新.
这是我的代码:
#include <iostream>
#include <vector>
#include <sys/time.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/tracking.hpp>
using namespace cv;
using namespace std;
//------------------------------------------------ convenience method for
// using kalman filter with
// Point objects
cv::KalmanFilter KF;
cv::Mat_<float> measurement(2,1);
Mat_<float> state(4, 1); // (x, y, Vx, Vy)
void initKalman(float x, float y)
{
// Instantate Kalman Filter with
// 4 dynamic parameters and 2 measurement parameters,
// where my measurement is: 2D location of object,
// and dynamic is: 2D location and 2D …Run Code Online (Sandbox Code Playgroud) 我在后端使用带有nodejs的ejs.我想在包含时传递变量.包含标题时,传递页面标题.
index.ejs:
<% include header %>
<body> . . . </body>
<% include footer%>
Run Code Online (Sandbox Code Playgroud)
header.ejs:
<html lang="en">
<head>
<title><%- my_tytle %></title>
</head>
Run Code Online (Sandbox Code Playgroud)
footer.ejs:
</html>
Run Code Online (Sandbox Code Playgroud)
如何传入my_titleinclude命令?
我写了这个简单的脚本来理解引用是什么,并且我被卡在char数组上.
int numbers[5] = {3, 6, 9, 12, 15};
for (int i = 0; i < 5; i++)
{
cout << numbers[i] << endl;
cout << &numbers[i] << endl;
}
cout << "--------------" << endl;
char letters[5] = {'a', 'b', 'c', 'd', 'e'};
for (int i = 0; i < 5; i++)
{
cout << letters[i] << endl;
cout << &letters[i] << endl;
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
3
0xbffff958
6
0xbffff95c
9
0xbffff960
12
0xbffff964
15
0xbffff968
--------------
a
abcde
b
bcde …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用CSS为我的QT应用程序创建一个很酷的用户界面.
我有这个问题:我有一个QPushButton,当它在焦点上时,它有一个我要删除的矩形.这里有一些屏幕截图:


我试图添加一些东西(backgroundcolor,文本装饰等)
QPushButton:focus
Run Code Online (Sandbox Code Playgroud)
但它一直在突出......
一些提示?
这是QPushButton css代码:
QPushButton
{
color: #b1b1b1;
background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #565656, stop: 0.1 #525252, stop: 0.5 #4e4e4e, stop: 0.9 #4a4a4a, stop: 1 #464646);
border-width: 1px;
border-color: #1e1e1e;
border-style: solid;
border-radius: 6;
padding: 3px;
font-size: 12px;
padding-left: 5px;
padding-right: 5px;
}
QPushButton:pressed
{
background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #2d2d2d, stop: 0.1 #2b2b2b, stop: 0.5 #292929, stop: 0.9 #282828, …Run Code Online (Sandbox Code Playgroud) 我有一个cmake项目,其中我有一些模块,我使用Find - *.cmake在应用程序中包含共享模块.为了不考虑我添加的每个模块,我已经LIB为链接器定义了一种全局变量:
# inside a Find-*.cmake or in the CMakeLists.txt of the modules:
set(LIB ${LIB} ...)
Run Code Online (Sandbox Code Playgroud)
所以在一个使用某些模块的最终应用程序中,我可以这样做:
target_link_libraries(${APP_NAME} ${LIB})
Run Code Online (Sandbox Code Playgroud)
然后,我想将已编译的模块放入其中,/project_path/modules/foo/build这样如果一个模块真的很难编译,那么可以为使用它的所有应用程序编译一次.我实现这一点的方法是以这种方式从Find - *.cmake加载模块的CMakeLists.txt:
# Inside FindFoo.cmake, for loading /project_path/modules/foo/CMakeLists.txt
# and compile it in /project_path/modules/foo/build
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../modules/${PACKAGE_NAME}
${CMAKE_CURRENT_LIST_DIR}/../modules/${PACKAGE_NAME}/build
)
include_directories(${CMAKE_CURRENT_LIST_DIR}/../modules/${PACKAGE_NAME}/include)
Run Code Online (Sandbox Code Playgroud)
但有时会发生某些模块需要另一个模块以便add_subdirectory创建新的作用域并且可以正确加载LIB但无法写入它(当我使用set它时,它在更深的范围内而不会更改上限范围).为了绕过此我要补充PARENT_SCOPE中set)..所以我试图将它添加一些模块,我认为可以嵌套,并隐藏在一些依赖,但编译所有我突然面对的应用程序:
CMake Warning (dev) at /path_to_repo/cmake/FindFooX.cmake:6 (set):
Cannot set "LIB": current scope has no parent.
Call Stack (most recent call first):
CMakeLists.txt:14 (find_package)
This warning is for …Run Code Online (Sandbox Code Playgroud)