我遇到了这个问题,询问如何在C中的main()之前执行代码,并提到C++的策略.我主要住在应用程序空间,所以在main()之前执行从未发生过.什么样的东西需要这种技术?
我正在设计自己的增强现实应用程序.我已经检测到我正在使用的模式的4个角.在以正确的顺序检测到4个角后,我将它们传递给cvFindExtrinsicCameraParams2.对于相机框架的旋转和平移,我得到了很好的结果.现在我必须把这些信息(旋转矢量和翻译矢量)放到OpenGL中来绘制一些东西.当然,我正在使用cvRodrigues2从旋转矢量中获取旋转矩阵.除此之外,我用这种方式用QGlWidget观看相机:
GLWidget.h
#ifndef _GLWIDGET_H
#define _GLWIDGET_H
#include <QtOpenGL/QGLWidget>
#include <cv.h>
#include <cxcore.h>
class GLWidget : public QGLWidget {
Q_OBJECT // must include this if you use Qt signals/slots
public:
GLWidget(QWidget *parent = NULL);
IplImage *img;
void setImage(IplImage *imagen);
protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
};
#endif /* _GLWIDGET_H */
Run Code Online (Sandbox Code Playgroud)
GLWidget.cpp
#include <QtGui/QMouseEvent>
#include "GLWidget.h"
GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {
this->img = 0;
}
void GLWidget::initializeGL() {
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_COLOR_MATERIAL);
glEnable(GL_BLEND);
glEnable(GL_POLYGON_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0, 0, 0, …Run Code Online (Sandbox Code Playgroud) 这是 R n中点的 K 最近邻算法,它应该计算每个点与其 k 最近邻的平均距离。问题是,虽然它是矢量化的,但从我重复自己的意义上说,它是低效的。如果有人可以帮助我改进此代码,我会很高兴:
import numpy as np
from scipy.spatial.distance import pdist
from scipy.spatial.distance import squareform
def nn_args_R_n_squared(points):
"""Calculate pairwise distances of points and return the matrix together with matrix of indices of the first matrix sorted"""
dist_mat=squareform(pdist(points,'sqeuclidean'))
return dist_mat,np.argsort(dist_mat,axis=1)
def knn_avg_dist(X,k):
"""Calculates for points in rows of X, the average distance of each, to their k-nearest neighbours"""
X_dist_mat,X_sorted_arg=nn_args_R_n_squared(X)
X_matrices=(X[X_sorted_arg[:,1:k+1]]-X[...,None,...]).astype(np.float64)
return np.mean(np.linalg.norm(X_matrices,axis=2)**2,axis=1)
X=np.random.randn(30).reshape((10,3))
print X
print knn_avg_dist(X,3)
Run Code Online (Sandbox Code Playgroud)
输出:
[[-1.87979713 0.02832699 0.18654558]
[ 0.95626677 0.4415187 -0.90220505]
[ …Run Code Online (Sandbox Code Playgroud) 如何使用apache-benchmark测试php应用程序的性能?
我的环境是Ubuntu Linux - 我可以安装包吗?
<?php
include"include/connection.php";
$checkusername=mysql_query("SELECT * FROM employer WHERE eusername='$username'");
if (mysql_num_rows($checkusername)==1)
{
echo "username already exist";
}
else
{
$query = "insert into employer(efname,elname,egender,eemail,eusername,epwd,eadd,ephone,ecity,ecountry) values ('".$_POST['first_name']."','".$_POST['last_name']."','".$_POST['gender']."','".$_POST['email']."','".$_POST['username']."','".$_POST['password']."','".$_POST['address']."','".$_POST['phone']."','".$_POST['city']."','".$_POST['country']."')";
$result = mysql_query($query) or die (mysql_error());
echo " Thanks for registration";
}
?>
Run Code Online (Sandbox Code Playgroud)
这是我将注册表单数据插入数据库的代码.此代码添加数据但也提供解析错误,但如果用户名已存在则不会给出错误.
Notice: Undefined variable: username in C:\Program Files\EasyPHP5.3.0\www\register_hirer2.php on line 6
Thanks for registration
Run Code Online (Sandbox Code Playgroud)
第6行是:
$checkusername=mysql_query("SELECT * FROM employer WHERE eusername='$username'");
Run Code Online (Sandbox Code Playgroud)