• 大小: 14.42MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-13
  • 语言: 其他
  • 标签: opencv  

资源简介

在智能小车上(Arduino、主控板)搭载wifi模块和摄像头,发送数据到电脑,vs2013处理数据后发回小车,达到实时视频监测和远程遥控控的目的,所有代码都是用txt文档保存的,直接在vs中复制即可。(需提前配置好opencv3.0)

资源截图

代码片段和文件信息


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

HANDLE hComm;
OVERLAPPED m_ov;
COMSTAT comstat;


using namespace cv;
using namespace std;

Mat image;
bool backprojMode = false;//表示是否要进入反向投影模式,ture表示准备进入反向投影模式 
bool selectobject = false;//代表是否在选要跟踪的初始目标,true表示正在用鼠标选择
int trackobject = 0;//代表跟踪目标数目
bool showHist = true;//是否显示直方图 
Point origin;//用于保存鼠标选择第一次单击时点的位置 
Rect selection;//用于保存鼠标选择的矩形框 
int vmin = 10 vmax = 256 smin = 30;



static void onMouse(int event int x int y int void*)
{
if (selectobject)//只有当鼠标左键按下去时才有效,然后通过if里面代码就可以确定所选择的矩形区域selection了  
{
selection.x = MIN(x origin.x);
selection.y = MIN(y origin.y);
selection.width = std::abs(x - origin.x);
selection.height = std::abs(y - origin.y);
selection &= Rect(0 0 image.cols image.rows);//用于确保所选的矩形区域在图片范围内  
}

switch (event)
{
case EVENT_LBUTTONDOWN:
origin = Point(x y);
selection = Rect(x y 0 0);//鼠标刚按下去时初始化了一个矩形区域 
selectobject = true;
break;
case EVENT_LBUTTONUP:
selectobject = false;
if (selection.width > 0 && selection.height > 0)
trackobject = -1;
break;
}
}
//c - 停止追踪\n“
//b - 开/关-投影视图\n“
//h - 显示/隐藏-对象直方图\n“
//p - 暂停视频\n“;
const char* keys =
{
“{1|  | 0 | camera number}“
};





bool ProcessErrorMessage(char* ErrorText)
{
char *Temp = new char[200];
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
NULL
GetLastError()
MAKELANGID(LANG_NEUTRAL SUBLANG_DEFAULT) // Default language
(LPTSTR)&lpMsgBuf
0
NULL
);
sprintf(Temp “WARNING: %s Failed with the following error: \n%s\nPort: %d\n“ (char*)ErrorText lpMsgBuf “com2“);
MessageBox(NULL Temp “Application Error“ MB_IConstop);
LocalFree(lpMsgBuf);
delete[] Temp;
return true;
}

bool openport(char *portname)//打开一个串口
{

hComm = CreateFile(portname
GENERIC_READ | GENERIC_WRITE
0
0
OPEN_EXISTING
FILE_FLAG_OVERLAPPED
0);
if (hComm == INVALID_HANDLE_VALUE)
return FALSE;
else
return true;
}

bool setupdcb(int rate_arg)
{
DCB dcb;
int rate = rate_arg;
memset(&dcb 0 sizeof(dcb));
if (!GetCommState(hComm &dcb))//获取当前DCB配置
{
ProcessErrorMessage(“GetCommState()“);
return FALSE;
}
/* -------------------------------------------------------------------- */
// set DCB to configure the serial port
dcb.DCBlength = sizeof(dcb);
/* ---------- Serial Port Config ------- */
dcb.BaudRate = rate;
dcb.Parity = NOPARITY;
dcb.fParity = 0;
dcb.StopBits = ONESTOPBIT;
dcb.ByteSize = 8;
dcb.fOutxCtsFlow = 0;
dcb.fOutxDsrFlow = 0;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fDsrSensitivity = 0;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fOutX = 0;
dcb.fInX = 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-12-25 20:10  CAMEROCAR\CAR1\
     文件         691  2015-08-29 14:12  CAMEROCAR\CAR1\CAR.ino
     目录           0  2015-12-25 20:10  CAMEROCAR\CAR2\
     文件         751  2015-08-29 13:57  CAMEROCAR\CAR2\CAR2.ino
     目录           0  2015-12-25 20:10  CAMEROCAR\CAR3\
     文件        1547  2015-08-29 15:45  CAMEROCAR\CAR3\CAR3.ino
     目录           0  2015-12-25 20:10  CAMEROCAR\CAR4\
     文件        4418  2015-08-23 14:30  CAMEROCAR\CAR4\CAR4.ino
     目录           0  2015-12-25 20:10  CAMEROCAR\CAR5\
     文件        4438  2015-08-23 17:30  CAMEROCAR\CAR5\CAR5.ino
     文件         667  2015-08-28 17:53  CAMEROCAR\Opencv获取网络摄像头demo.txt
     文件         812  2015-08-29 14:44  CAMEROCAR\wifi发送数据改进版demo.txt
     文件        1033  2015-08-29 14:15  CAMEROCAR\wifi发送数据原demo.txt
     文件        7494  2015-08-26 11:00  CAMEROCAR\串口调试demo.txt
     目录           0  2015-12-25 20:10  CAMEROCAR\串口通讯2\
     目录           0  2015-12-25 20:10  CAMEROCAR\串口通讯2\.vs\
     目录           0  2015-12-25 20:10  CAMEROCAR\串口通讯2\.vs\Godhelpme\
     目录           0  2015-12-25 20:10  CAMEROCAR\串口通讯2\.vs\Godhelpme\v14\
     文件       20480  2015-08-19 13:09  CAMEROCAR\串口通讯2\.vs\Godhelpme\v14\.suo
     目录           0  2015-12-25 20:10  CAMEROCAR\串口通讯2\arduino\
     文件        1083  2015-08-26 14:34  CAMEROCAR\串口通讯2\arduino\arduino.ino
     目录           0  2015-12-25 20:10  CAMEROCAR\串口通讯2\bbbbbbbbbbbb\
     文件         883  2015-08-26 14:03  CAMEROCAR\串口通讯2\bbbbbbbbbbbb\bbbbbbbbbbbb.ino
     目录           0  2015-12-25 20:10  CAMEROCAR\串口通讯2\camshift\
     文件        1032  2015-08-27 17:27  CAMEROCAR\串口通讯2\camshift\camshift.ino
     文件       13408  2015-08-27 17:27  CAMEROCAR\串口通讯2\camshift\彩色目标追踪-串口通讯cpp.cpp
     目录           0  2015-12-25 20:10  CAMEROCAR\串口通讯2\Debug\
     文件       54784  2015-08-23 17:21  CAMEROCAR\串口通讯2\Debug\Godhelpme.exe
     文件      907492  2015-08-23 17:21  CAMEROCAR\串口通讯2\Debug\Godhelpme.ilk
     文件     1149952  2015-08-23 17:21  CAMEROCAR\串口通讯2\Debug\Godhelpme.pdb
     文件    39387136  2015-08-23 17:31  CAMEROCAR\串口通讯2\Godhelpme.sdf
............此处省略78个文件信息

评论

共有 条评论