《学习OpenCV》练习题第四章第四题

OPENCV面试题 1.opencv中RGB2GRAY是怎么实现的 答:以R、G、B为轴建立空间直角坐标系,则RGB图的每个象素的颜色可以用该三维空间的一个点来表示,而Gray图的每个象素的颜色可以用直线R=G=B上的一个点来表示。于是rgb转gray图的本质就是寻找一个三维空间到一维空间的映射,最容易想到的就是射影(即过rgb空间的一个点向直线R=G=B做垂线),事实上Matlab也是这样做的,输出的灰度图像是RGB三种颜色通道的加权和; Gray = 0.29900 * R + 0.58700 * G + 0.11400 阅读详情
#include <highgui.h>
#include <cv.h>
#include "opencv_libs.h"

/*
 *《学习OpenCV》第四章第四题
 * 完成时间:1:36 3/31 星期日 2013
 */

int g_slider_position = 0;
CvCapture* g_capture = NULL;

int i = 0;
int g_slider_position1 = 0;
bool t = true;


void onTrackbarSlide(int pos)
{
	cvSetCaptureProperty ( g_capture, CV_CAP_PROP_POS_FRAMES, pos );
	i = pos;
}

void switch_callback(int position)
{
	if(position == 0)
	{
		t = true;
	}
	else
	{
		t = false;
	}
}

int main()
{
	cvNamedWindow("Video", CV_WINDOW_AUTOSIZE);
	
	g_capture = cvCaptureFromFile("1111.avi");
	int frames = (int)cvGetCaptureProperty( g_capture, CV_CAP_PROP_FRAME_COUNT );

	if(frames != 0)
	{
		cvCreateTrackbar( "Position", "Video", &g_slider_position, frames, onTrackbarSlide);
		cvCreateTrackbar( "Position1", "Video", &g_slider_position1, 1, switch_callback);
	}
	cvSetTrackbarPos("Position", "Video", 1 );
	cvSetTrackbarPos("Position1", "Video", 0 );

	IplImage * frame;
	while( (frame= cvQueryFrame(g_capture)) != NULL)
	{
		char c = cvWaitKey(50);
		if(c == 27)
			break;
		cvShowImage("Video", frame);
		cvSetTrackbarPos("Position", "Video", i);

		if(t)
		{
			i = i+ 10;  // 10为步长
			cvSetCaptureProperty( g_capture, CV_CAP_PROP_POS_FRAMES, i );
		}
		else
		{
			cvSetCaptureProperty( g_capture, CV_CAP_PROP_POS_FRAMES, i );
		}
	}

	cvReleaseCapture(&g_capture);
	cvReleaseImage(&frame);
	cvDestroyAllWindows();

	return 0;
}

运行结果:



不足:不知道为什么,播放的视频相当相当相当卡.....

《学习OpenCV》练习题第四章第六题 #include #include "opencv_libs.h" #include #define IMG_WIDTH 512 #define IMG_HEIGHT 512 /* *《学习OpenCV》第四章第六题 * 完成时间:9:32 4/5 星期五 2013 */ CvFont font; char *display_text = "|"; // 阅读详情

相关推荐

学习opencv3中文版--第四章答案

1. /* 本程序只实现了a和b,读者可自行实现c和d */ #include <opencv2/opencv.hpp> #include <iostream> using namespace std; const int display_height = 500; const int display_weight = 500; vector<cv::Mat1...

huqiaolong的博客 1307

《学习opencv》第四章第四题

读入并显示视频文件,创建两个滑动条: 1 控制视频播放位置,以10为步长跳进 2 控制视频的停止、播放 代码: // chapter4_4.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include<cv.h> #include<highgui.h> int g_slider_Position = 0;//两个滑动条的初始位置 int g_slider_Position1 = 0; CvCapture *g_capture =

我不是码农的博客~~~ 363

《学习OpenCV》第四章练习题4

#include<iostream> #include"highgui.h" #include"cv.h" using namespace std; using namespace cv;CvRect rect; IplImage* test = cvLoadImage("test.jpg"); IplImage* test1 = cvCreateImage(cvSize(test->width,

Goods222的博客 460

OpenCV图形处理基本概念

十道选择题: 1.图像常见的格式有 A.jpg   B.tiff  :主要用来存储包括照片和艺术图在内的图像,占用空间较大。 C.png D.webp:旨在加快图片加载速度的图片格式。图片压缩体积大约只有JPEG的2/3,不过编码时间"比JPEG格式图像长8倍"。 2.常见的图像通道数可能是: A. 单通道 B.双通道 C. 三通道:RGB D.四通道 3.数字图像中最小数据...

qq_26658517的博客 816

学习openCV第四章答案

第一题: #include "cv.h" #include "highgui.h" #pragma comment(lib,"cv.lib") #pragma comment(lib,"cxcore.lib") #pragma comment(lib,"highgui.lib") int main(int argc, char** argv) { CvCapture* capture =

LJH0600301217的专栏 2059

opencv题目

opencv题目

Opencv学习之:基础概念

Opencv像素的数据类型是以下列方式表达的:CV_ABCD. A:每个像素多少位。 B:是否有正负号。 C:类型前置码。 D:通道数。 例如:CV_8UC3表示:每个像素8位,没有正负号,用char表示像素,每个像素有三个通道。 RGB三原色使用CV_8UC3表示如下: (255,0,0):红色 (0,255,0):绿色 (0,0,255):蓝色 (0,0,0):黑色 (255...

Wu_qz的博客 768

【eNSP 华为模拟器】小型校园网模拟环境的设计与配置(附eNSP源文件)

【eNSP 华为模拟器】小型校园网模拟环境的设计与配置 一、实验概述 二、交换机的配置 2.1 二层交换机的配置 2.2 三层交换机的配置 三、路由器的配置 四、实验结果 五、实验总结 一、实验概述 按照以下的拓扑连接,自行设计VLAN和IP地址等网络参数,实现PC1到PC2的IP通信。其中,R1,R2为路由器;LSW1,LSW4为3层交换机;LSW2,LSW3 ,LSW6, LSW7为2层交换机;CLIENT1-CLIENT12为PC机。 拓扑图 课程设计要求:(1)IP地址自行规划设计,应该清晰地

qq_43757282的博客 4万+

《学习OpenCV》练习题第四章第一题a

#include #include #pragma comment (lib,"opencv_calib3d231d.lib") #pragma comment (lib,"opencv_contrib231d.lib") #pragma comment (lib,"opencv_core231d.lib") #pragma comment (lib,"opencv_features2d23

qdsclove的专栏 1529

手把手教你用C语言实现GNSS卫星方位角计算(附RTKLIB风格代码解析)

本文详细介绍了如何使用C语言实现GNSS卫星方位角计算,包括从地固坐标系到站心坐标系的转换链条。通过RTKLIB风格的代码解析,展示了XYZ到ENU坐标转换的核心原理和C语言实现框架,帮助开发者掌握卫星方位角和高度角的计算技巧,适用于GNSS观测数据质量分析和精密定位算法开发。

weixin_30699915的博客 364

stata:stata软件教程(人大十八讲)(1) 第一章 stata入门

第一章 stata入门1.1 安装1.2 启用和退出1.3 打开和查看数据1.4 寻求帮助与网络资源1.5 命令示例1.6 几个环境设置1.7 复习与练习1.8 附录 注:教材为:Stata 统计分析教程 stata软件教程(人大十八讲) 中国人民大学出版社 陈传波 1.1 安装 1.2 启用和退出 1.3 打开和查看数据 1.4 寻求帮助与网络资源 1.5 命令示例 1.6 几个环境设置 1.7 复习与练习 1.8 附录 ...

qq_47805483的博客 1万+

《学习OpenCV》练习题第四章第五题a

#include "opencv_libs.h" #include #include #include /* *《学习OpenCV》第四章第五题a * 完成时间:8:08 4/5 星期五 2013 */ #define IMG_WIDTH 512 // 图像宽 #define IMG_HEIGHT 512 // 图像高 #define RAND_INT_MAX 256

qdsclove的专栏 2209

EDSR图像超分辨程序复现(踩坑及解决记录)

EDSR图像超分辨程序复现(踩坑及解决记录)

Sunny_Coder的博客 3642

《学习OpenCV》练习题第四章第二题

#include #include #pragma comment (lib,"opencv_calib3d231d.lib") #pragma comment (lib,"opencv_contrib231d.lib") #pragma comment (lib,"opencv_core231d.lib") #pragma comment (lib,"opencv_features2d23

qdsclove的专栏 1398

R语言机器学习算法实战系列(十五)随机森林生存预后模型+SHAP值 (Random Survival Forest + SHAP)

本教程运用随机森林生存分析筛选与患者生存状态显著相关特征。该方法借随机森林这一强大机器学习算法,构建多棵决策树并集成结果,以提高生存分析准确性,识别关键生物标志物。接着,利用选定特征构建风险得分,将多个特征转化为单一数值,量化患者风险水平。之后,依据风险得分将患者分为高、低风险亚型,为临床治疗提供个性化指导。最后,通过分析时间依赖的 ROC 曲线评估模型长期预测能力。此曲线计算不同阈值下的真正例率与假正例率,在多个时间点评估,全面展现模型长期稳定性与准确性。。并且增加了SHAP值评估特征重要性

专注生信领域 2621

基于STM32、HAL库的BMP585 气压传感器 驱动程序设计

define BMP585_I2C_ADDR_PRIMARY 0x76 << 1 /* 0x76地址左移一位 */#define BMP585_I2C_ADDR_SECONDARY 0x77 << 1 /* 0x77地址左移一位 *//* I2C句柄 *//* I2C地址 *//* 设置新的温度过采样率 *//* 设置新的滤波器系数 *//* 芯片ID *//* 清除温度过采样位 *//* 转换为hPa *//* 设置新的压力过采样率 *//* 设置新的电源模式 *//* 清除压力过采样位 */

corlin6688的博客 459

《学习OpenCV》练习题第四章第七题abc

题外话:一直是打算把这本书的全部课后编程题写完的,中间断了几个月,一直忙于其他事。现在开始补上。 这道题我不清楚我理解的题意是不是正确的,这道题可以练习用OpenCV实现透视变换(可以用于矫正在3维环境下的图像失真),b&c部分则是实现图像放大缩小插值,旋转图像。所有的功能都和键盘事件处理联系起来,纯OpenCV实现,和OS无关。不过,在处理SHIFT键时,我取得是其在键盘上对应字符的ASCII

qdsclove的专栏 1614

【学术情报智库】目录学的数字化蜕变:从古籍整理到AI知识图谱的跨越

我们既是浩瀚知识的守望者,也是数字智识的开拓者。目录学数字化不是技术替代传统,而是融合创新,让学术的系统性与多样性在新媒介下焕发新的生命。以AI为桥,既要智能链接,也要人文关照——这是对自我文明的深情回应,也是新知时代的庄严约定。

高校图书馆高级系统架构师/研究馆员,推动高校AI从概念演示到可评审、可交付、可运维:路线图与立项评审、PoC交付、评测回归与上线运维(Baseline/Eval/Ops)。 1420

《学习OpenCV》练习题第四章第八题ab

这道题是利用OpenCV例子程序里自带的人脸检测程序,做点图像的复制操作以及alpha融合。 说明:人脸检测的程序我参照了网上现有的例子程序,没有用我用的OpenCV版本(2.4.5)的facedetect.c,人脸检测部分是一个月前写的程序,这次做这道理,做了点改动,以前的部分注释了起来。 代码: #include #include #include #inclu

qdsclove的专栏 1512

手把手教你完成YOLOv9 PyQt5目标检测界面搭建,实现图片检测、视频检测、摄像头检测,可用于大论文凑工作量或毕设必备,全网最详细教程

目标检测是计算机视觉中的重要任务,广泛应用于安防监控、自动驾驶、智能家居等领域。YOLO系列模型由于其高效的检测速度和较高的准确率,成为目标检测任务的首选算法之一。本项目结合 YOLOv9与 PyQt5,构建了一个图形化界面,便于用户进行目标检测的操作和展示,实现对图片、视频和摄像头的实时目标检测,不仅可以用于大论文的工作量展示,还可以作为毕业设计。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 2657

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

《学习OpenCV》练习题第四章第三题b

#include #include #include "opencv_libs.h" /* *《学习OpenCV》第四章第三题b * 完成时间:1:36 3/31 星期日 2013 */ /* 矩形框 */ CvRect rect; bool draw = false; // 标记是否在画 IplImage* img; IplImage * temp; IplImage *

qdsclove的专栏 1209

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

《学习OpenCV》练习题第四章第一题b&c

#include #include #pragma comment (lib,"opencv_calib3d231d.lib") #pragma comment (lib,"opencv_contrib231d.lib") #pragma comment (lib,"opencv_core231d.lib") #pragma comment (lib,"opencv_features2d23

qdsclove的专栏 1685

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

《学习OpenCV》练习题第四章第三题a

#include #include #include "opencv_libs.h" #pragma comment (lib,"opencv_calib3d231d.lib") #pragma comment (lib,"opencv_contrib231d.lib") #pragma comment (lib,"opencv_core231d.lib") #pragma comment

qdsclove的专栏 1300

《学习OpenCV》练习题第二章第四题

#include #include #pragma comment (lib,"opencv_calib3d231d.lib") #pragma comment (lib,"opencv_contrib231d.lib") #pragma comment (lib,"opencv_core231d.lib") #pragma comment (lib,"opencv_features2d23

qdsclove的专栏 1152

《学习OpenCV》练习题第三章第四题

#include #include #include #pragma comment (lib,"opencv_calib3d231d.lib") #pragma comment (lib,"opencv_contrib231d.lib") #pragma comment (lib,"opencv_core231d.lib") #pragma comment (lib,"opencv_fe

qdsclove的专栏 1262

学习opencv第四章第三题

#include "cv.h" #include "highgui.h" #pragma comment(lib,"cv.lib") #pragma comment(lib,"highgui.lib") #pragma comment(lib,"cxcore.lib") void my_mouse_callback(int event,int x, int y, int flag, void*

LJH0600301217的专栏 1459
上一篇: 《学习OpenCV》练习题第四章第三题b
下一篇: 《学习OpenCV》练习题第四章第五题a
Stk_OverFlow
博客等级 码龄14年 27粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值