开放式视觉伺服平台源代码_上位机(初步版本,未对细节做修订)

/***********************************************************************
 * 开放式视觉伺服平台测试例程
 * 作者:李智超(西北工业大学)
 * 如需转载,请注明出处
 * 测试环境为Ubuntu13.04 默认g++

 * Originally created 15 June 2013
 * Copyleft (c) 2013, Vicent_Lee
 * http://blog.csdn.net/u010305560
 ***********************************************************************/


#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

#include <iostream>
#include <ctype.h>
#include <stdio.h>    // Standard input/output definitions 
#include <stdlib.h> 
#include <string.h>   // String function definitions 
#include <unistd.h>   // for usleep()
#include <stdint.h>
#include <fcntl.h>    // File control definitions 
#include <errno.h>    // Error number definitions 
#include <termios.h>  // POSIX terminal control definitions 
#include <sys/ioctl.h>
#include <math.h>
using namespace cv;
using namespace std;

int serialport_init(const char* serialport, int baud);
int serialport_close(int fd);
int serialport_write(int fd, const char* str);
int serialport_flush(int fd);
void error(const char* msg);
void send_pos_error(int fd, float x, float y);
void open_serial();
void help();
void onMouse( int event, int x, int y, int, void* );


Mat image;

bool backprojMode = false; //表示是否要进入反向投影模式,ture表示准备进入反向投影模式
bool selectObject = false;//代表是否在选要跟踪的初始目标,true表示正在用鼠标选择
int trackObject = 0; //代表跟踪目标标识 trackObject初始化为0,或者按完键盘的'c'键后也为0,当鼠标单击松开后为-1
bool showHist = true;//是否显示直方图
Point origin;//用于保存鼠标选择第一次单击时点的位置
Rect selection;//用于保存鼠标选择的矩形框
int vmin = 10, vmax = 256, smin = 30;


char serialport[20];
int baudrate = 19200; 
int fd=-1;

const char* keys = 
{
    "{1|  | 0 | camera number}"
};

/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
int speed_max=20;//servo_rotate_speed=2*speed_max 度/s
int P=10;//PID pararmeter
int xc=1560;
int yc=1590;
int xc_last=1560;
int yc_last=1590;
double x_tune=0;
double y_tune=0;
int send_delay_cnt=0;
double x_tune_last=0;
double y_tune_last=0;
/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/


int main( int argc, const char** argv )
{
    help();

    VideoCapture cap; //定义一个摄像头捕捉的类对象
    Rect trackWindow; //trackWindow为鼠标选择的区域
    RotatedRect trackBox;//定义一个旋转的矩阵类对象
    int hsize = 16;
    float hranges[] = {0,180};//hranges在后面的计算直方图函数中要用到
    const float* phranges = hranges;
    CommandLineParser parser(argc, argv, keys);//命令解析器函数
    int camNum = parser.get<int>("1");     
    
    cap.open(camNum);//直接调用成员函数打开摄像头

    if( !cap.isOpened() )
    {
        help();
        cout << "**
  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值