// OpenCV_Cam.cpp : 此檔案包含 'main' 函式。程式會於該處開始執行及結束執行。
//
#include <iostream>
#include <opencv2/highgui.hpp>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
bool m_IsTest;
int m_Image_count;
int m_Before_Image_count;
int m_horizontal;
int m_vertical;
int m_SleepTime;
bool m_Need_Refreshed;
// 預設的視窗大小
int m_Required_Image_Width;
int m_Required_Image_Height;
//New Defiend
Mat org;//原图
Mat img;//输出图片
Mat imgROI;//感兴趣区域
Mat roiResize;//感兴趣区域ROI的两倍
Mat tranPart;
int foo = 50;//定义尺寸
int fooResize = 2 * foo;//最终显示放大镜的正方形区域的边长,用作下面if的判断
int pitch_x,pitch_y,w,L,zoom;
//cv::Rect crop(95, 31, 450, 412);
int P1X = 1 ,P1Y=1,P2X=450,P2Y=412;
int scale;
int temCurrentIndex;
double ScaleFactor;
int ZoomIndex = -1;
cv::Mat FrameMat[120];
cv::Mat FinalMat_Zoom;
int scale_inde=0;
bool scale_staus = false;
void CropImage_zoomin()
{
int width = (P2X - (pitch_x * (scale_inde))) - (P1X + (pitch_x * (scale_inde)));
int hight = (P2Y - (pitch_y * (scale_inde))) - (P1Y + (pitch_y * (scale_inde)));
Rect roi = Rect(P1X + (pitch_x * (scale_inde)), P1Y + (pitch_y * (scale_inde)), width, hight);
cv::Mat m1l = FrameMat[temCurrentIndex](roi);
cv::resize(m1l, FinalMat_Zoom, cv::Size(w, L));
}
void CropImage_zoomout()
{
//Rect roi = Rect(cx - (pitch_x * scale_inde), cy - (pitch_y *scale_inde), cx + (pitch_x *scale_inde), cy + (pitch_y * scale_inde));
//cv::Mat m1l = FrameMat[temCurrentIndex](roi);
//cv::resize(m1l, FinalMat_Zoom, cv::Size(w, L));
int width = (P2X - (pitch_x * (scale_inde))) - (P1X + (pitch_x * (scale_inde)));
int hight = (P2Y - (pitch_y * (scale_inde))) - (P1Y + (pitch_y * (scale_inde)));
Rect roi = Rect(P1X + (pitch_x * (scale_inde)), P1Y + (pitch_y * (scale_inde)), width, hight);
cv::Mat m1l = FrameMat[temCurrentIndex](roi);
cv::resize(m1l, FinalMat_Zoom, cv::Size(w, L));
}
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
if (event == EVENT_LBUTTONDOWN)
{
scale_inde = scale_inde + 1;
if (scale_inde >= 4)
{
scale_inde = 4;
}
CropImage_zoomin();
scale_staus = true;
ZoomIndex = 1;
//cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
}
else if (event == EVENT_RBUTTONDOWN)
{
if(scale_staus==true)
{
scale_inde = scale_inde - 1;
if (scale_inde == 0)
{
scale_inde = 0;
scale_staus = false;
ZoomIndex = -1;
}
else
{
scale_staus = true;
ZoomIndex = 2;
}
CropImage_zoomout();
}
//cout << "Right button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
}
else if (event == EVENT_MBUTTONDOWN)
{
// << "Middle button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
}
else if (event == EVENT_MOUSEMOVE)
{
////形参x,y是鼠标点击的位置
//Mat img_temp = img.clone();//临时变量,存放原图
////if的作用,x,y是鼠标坐标,限定不能太靠近左上角x > fooResize和 y>fooResize,目的是能让放大镜显示出来。
////同时限定不能太靠近右下角x<img_temp.cols - fooResize和 y < img_temp.rows - fooResize
//if (x > fooResize && x<img_temp.cols - fooResize && y>fooResize && y < img_temp.rows - fooResize) {
// //感兴趣区域范围
// imgROI = img_temp(Rect(x - foo, y - foo, 2 * foo, 2 * foo));//以(x,y)为中心,左右为foo做正方形
// //tranPart是最后显示放大的区域,这里
// tranPart = img_temp(Range(y - 2 * foo, y + 2 * foo), Range(x - 2 * foo, x + 2 * foo));//Range表示纵、横坐标的范围
// //感兴趣区域放大两倍,需要和tranPart的尺寸搭配。可调,但是注意不能超过图片本身范围。
// resize(imgROI, roiResize, Size(2 * imgROI.cols, 2 * imgROI.rows));//输出到roiResize这个Mat对象中
// roiResize.copyTo(tranPart);//复制到tranPart这个Mat对象中
// //标注鼠标的位置
// circle(img_temp, Point(x, y), 10, Scalar(0, 0, 255), 1, 8, 0);//画一个简单的圆
// imshow("img", img_temp);//显示窗口
// //cout << "Mouse move over the window - position (" << x << ", " << y << ")" << endl;
//}
}
}
int main()
{
cv::VideoCapture cap(0);
//cv::VideoCapture cap("C:\\work\\Remex\\program\\CaptureVideo_test_1\\test_video.mp4");
cap.grab();
clock_t a, b, c;
cv::Mat frame;
//cv::Mat FinalMat = cv::Mat::zeros(m_Required_Image_Height, m_Required_Image_Width, CV_8UC3);
//cv::UMat FinalUMat = cv::UMat::zeros(FinalMat.rows, FinalMat.cols, frame.type());
//m_Required_Image_Width = 1600;
//m_Required_Image_Height = 1200;
m_Required_Image_Width = 800;
m_Required_Image_Height = 600;
ScaleFactor = m_Required_Image_Width / 675.0;
if (m_Required_Image_Height / 412.0 < ScaleFactor) ScaleFactor = m_Required_Image_Height / 412.0;
ScaleFactor = ScaleFactor * 0.9;
int NumAveFrame = 40;
cv::Mat Mask_Invisible_Part[120];
cv::Mat Mask_Visible_Part[120];
for (int i = 0; i < NumAveFrame; i++)
{
FrameMat[i] = cv::Mat::zeros(frame.rows, frame.cols, CV_8UC3);
Mask_Invisible_Part[i] = cv::Mat::zeros(frame.rows, frame.cols, CV_8UC1);
Mask_Visible_Part[i] = cv::Mat::zeros(frame.rows, frame.cols, CV_8UC1);
}
int CurrentIndex = -1;
bool NoError = true;
bool NoFirstOne = false;
cv::Mat temMat;
while (1)
{
a = clock();
// Capture frame-by-frame
cap >> frame;
// If the frame is empty, break immediately
if (frame.empty()) break;
if (m_Need_Refreshed)
{
CurrentIndex = -1;
NoFirstOne = false;
m_Need_Refreshed = false;
}
CurrentIndex++;
temCurrentIndex = CurrentIndex % NumAveFrame;
int PretemCurrentIndex = temCurrentIndex - 1;
if (PretemCurrentIndex < 0) PretemCurrentIndex = NumAveFrame - 1;
frame.copyTo(FrameMat[temCurrentIndex]);
if (CurrentIndex > 20000) CurrentIndex = NumAveFrame + temCurrentIndex;
if (m_IsTest)
{
m_Before_Image_count++;
cv::imwrite("0_B_" + std::to_string(m_Before_Image_count) + "_" + std::to_string(m_Image_count) + ".bmp", frame);
cv::imwrite("0_A_" + std::to_string(m_Before_Image_count) + "_" + std::to_string(m_Image_count) + ".bmp", FrameMat[temCurrentIndex]);
}
NoFirstOne = true;
cv::Mat FinalMat;
cv::Mat temFrame;
//cv::Rect crop(95, 31, 450, 412);
cv::Rect crop(P1X, P1Y, P2X, P2Y);
cv::Mat m1 = FrameMat[temCurrentIndex](crop);
w = 675 * ScaleFactor;
L = 412 * ScaleFactor;
//calculate pitch
pitch_x = (P2X - P1X) / 10;
pitch_y = (P2Y - P1Y) / 10;
//No Scale
cv::resize(m1, FinalMat, cv::Size(w, L));
if (m_IsTest)
{
m_Before_Image_count++;
cv::imwrite("0_B_" + std::to_string(m_Before_Image_count) + "_" + std::to_string(m_Image_count) + ".bmp", frame);
cv::imwrite("0_A_" + std::to_string(m_Before_Image_count) + "_" + std::to_string(m_Image_count) + ".bmp", FrameMat[temCurrentIndex]);
}
namedWindow("Remex");//创建opencv窗口
if(scale_staus==false)
{
cv::imshow("Remex", FinalMat);
}
else
{
switch (ZoomIndex)
{
case 1:
CropImage_zoomin();
break;
case 2:
CropImage_zoomout();
break;
default:
break;
}
cv::imshow("Remex", FinalMat_Zoom);
}
//img = FinalMat.clone();
setMouseCallback("Remex", CallBackFunc, NULL);
cv::waitKey(25);
}
cap.release();
}
// 執行程式: Ctrl + F5 或 [偵錯] > [啟動但不偵錯] 功能表
// 偵錯程式: F5 或 [偵錯] > [啟動偵錯] 功能表
// 開始使用的提示:
// 1. 使用 [方案總管] 視窗,新增/管理檔案
// 2. 使用 [Team Explorer] 視窗,連線到原始檔控制
// 3. 使用 [輸出] 視窗,參閱組建輸出與其他訊息
// 4. 使用 [錯誤清單] 視窗,檢視
没有合适的资源?快使用搜索试试~ 我知道了~
visual studio 2022 C ++ Opecv cam 及時圖片放大縮小 VideoCapture
共54个文件
tlog:22个
ipch:5个
pdb:4个
需积分: 0 0 下载量 3 浏览量
2024-05-08
16:25:14
上传
评论
收藏 64.39MB ZIP 举报
温馨提示
Opecv cam 及時圖片放大縮小 VideoCapture 及時圖片放大縮小
资源推荐
资源详情
资源评论
收起资源包目录
OpenCV_Cam.zip (54个子文件)
OpenCV_Cam
.vs
OpenCV_Cam
v17
DocumentLayout.json 1KB
Browse.VC.db 25.63MB
Solution.VC.db 428KB
.suo 47KB
ipch
AutoPCH
ff44af47a33c6fb9
ZOOM.ipch 36.13MB
7f8b66bd9225e7db
OPENCV_CAM.ipch 118.69MB
21a9e8c0b38d3adb
EXE_COMMON.ipch 4.38MB
6741069020df59e5
EXE_COMMON.ipch 4.38MB
6dcee1c1ed7e98f1
OPENCV_CAM.ipch 115.19MB
FileContentIndex
725c8cf9-f785-4baa-aadf-4e93836039f1.vsidx 10KB
a468d703-1616-46c4-b444-d794acb1e7b9.vsidx 22KB
x64
Release
OpenCV_Cam.pdb 2.17MB
OpenCV_Cam.exe 27KB
Debug
OpenCV_Cam.pdb 1.5MB
OpenCV_Cam.sln 1KB
OpenCV_Cam
OpenCV_Cam.vcxproj.user 168B
OpenCV_Cam.vcxproj.filters 975B
x64
Release
vc143.pdb 1.81MB
OpenCV_Cam.obj 3.41MB
OpenCV_Cam.exe.recipe 307B
OpenCV_Cam.iobj 387KB
OpenCV_Cam.tlog
CL.write.1.tlog 432B
OpenCV_Cam.lastbuildstate 169B
Cl.items.tlog 141B
link.secondary.1.tlog 234B
CL.command.1.tlog 838B
link.command.1.tlog 1KB
link.read.1.tlog 4KB
link.write.1.tlog 422B
CL.read.1.tlog 39KB
OpenCV_Cam.ipdb 142KB
OpenCV_Cam.log 1KB
Debug
vc143.pdb 1.84MB
OpenCV_Cam.obj 467KB
OpenCV_Cam.tlog
unsuccessfulbuild 0B
link-rc.read.1.tlog 2B
CL.write.1.tlog 564B
link.read.2.tlog 2B
OpenCV_Cam.lastbuildstate 167B
link.read.3.tlog 2B
link.read.5.tlog 2B
CL.command.1.tlog 830B
link.command.1.tlog 2B
link-rc.write.1.tlog 2B
link-cvtres.read.1.tlog 2B
link.read.1.tlog 2B
link.write.1.tlog 2B
link-cvtres.write.1.tlog 2B
link.read.4.tlog 2B
CL.read.1.tlog 39KB
vc143.idb 363KB
OpenCV_Cam.log 5KB
OpenCV_Cam.vcxproj 7KB
OpenCV_Cam.cpp 8KB
共 54 条
- 1
资源评论
wade807
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于ARM的指令调度和延迟分支
- 基于Vue和TypeScript的极简聊天应用设计源码 - HasChat
- 基于Vue2全家桶和Zcool数据的图片收集网站设计源码 - cool-picture
- 基于C和C++的二维绘制工具设计源码 - DrawPro
- Object.defineProperty 的 IE 补丁object-defineproperty-ie-master.zip
- 整卷预览.mhtml
- MySQL是一种广泛使用的开源关系型数据库管理系统,它提供了丰富的SQL语句用于数据库的创建、查询、更新和管理 以下是一些常见的
- MySQL是一种广泛使用的开源关系型数据库管理系统,它提供了丰富的SQL语句用于数据库的创建、查询、更新和管理 以下是一些常见
- MySQL是一种广泛使用的开源关系型数据库管理系统,它提供了丰富的SQL语句用于数据库的创建、查询、更新和管理 以下是一些常见的
- 基于Javascript的结婚请帖设计源码 - Invitation
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功