热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

双运放

本文主要介绍关于snakecvSnakeImage,升级改进opencv3.0的知识点,对【图像处理之其他杂项(三)之cvSnakeImage改进升级兼容适用于opencv2,,在open

本文主要介绍关于snake cvSnakeImage,升级改进 opencv 3.0的知识点,对【图像处理之其他杂项(三)之cvSnakeImage改进升级兼容 适用于opencv2,,在opencv3.0以上版本中测试通过】和【双运放】有兴趣的朋友可以看下由【Coming_is_winter】投稿的技术文章,希望该技术和经验能帮到你解决你所遇的【# 图像处理其他杂项】相关技术问题。

双运放

cvSnakeImage改进升级兼容 ?   cvSnakeImage函数在opencv2中已经被去掉,现在函数仅有C接口版本,把函数源代码作为独立函数整合进程序中,并对其中包含的opencv2中不存在的函数宏定义进行更改替换,适合opencv2环境使用,测试环境VS2015+opencv3.2。   原源代码: 蚂蚁搬家   http://blog.csdn.net/hongxingabc/article/details/51606520   主动轮廓线模型Snake模型简介&openCV中cvSnakeImage()函数代码分析 ?    主要改进: ? ? ?   1. (1) CvSepFilter pX, pY;      (2) pX.init_deriv(TILE_SIZE + 2, CV_8UC1, CV_16SC1, 1, 0, 3);       ? ? pY.init_deriv(TILE_SIZE + 2, CV_8UC1, CV_16SC1, 0, 1, 3); ? ? ? ?   (3) pX.process(&_src1, &_dx); pY.process(&_src1, &_dy); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?改成:cvSobel(&_src1, &_dx, 1, 0, 1); ? ??cvSobel(&_src1, &_dy, 1, 0, 1); ?     2.加入宏定义:CV_VALUE=30; ? ? ? ? ? ? ? 3.注释掉CV_ERROR相关代码等。 ?     代码具体工作原理还未深入研究,最后不知是修改的代码哪里存在问题,还是snake的工作机制原因,算法只对特定图片的特定参数设置有反应,如测试的几张图片,只有一张云层的图片测试比较正常,可以达到预期效果,有待进一步研究,如若测试时效果不理想,不如试一下此云层图片。
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                        Intel License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//
//   * The name of Intel Corporation may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "cv.h"  

#define _CV_SNAKE_BIG 2.e+38f  
#define _CV_SNAKE_IMAGE 1  
#define _CV_SNAKE_GRAD  2  
#define CV_VALUE 30

/*F///
//    Name:      icvSnake8uC1R
//    Purpose:
//    Context:
//    Parameters:
//               src - source image,
//               srcStep - its step in bytes,
//               roi - size of ROI,
//               pt - pointer to snake points array
//               n - size of points array,
//               alpha - pointer to coefficient of continuity energy,
//               beta - pointer to coefficient of curvature energy,
//               gamma - pointer to coefficient of image energy,
//               coeffUsage - if CV_VALUE - alpha, beta, gamma point to single value
//                            if CV_MATAY - point to arrays
//               criteria - termination criteria.
//               scheme - image energy scheme
//                         if _CV_SNAKE_IMAGE - image intensity is energy
//                         if _CV_SNAKE_GRAD  - magnitude of gradient is energy
//    Returns:
//F*/

int icvSnake8uC1R(unsigned char *src,   //原始图像数据  
	int srcStep,         //每行的字节数  
	CvSize roi,         //图像尺寸  
	CvPoint * pt,       //轮廓点(变形对象)  
	int n,            //轮廓点的个数  
	float *alpha,       //指向α的指针,α可以是单个值,也可以是与轮廓点个数一致的数组  
	float *beta,        //β的值,同α  
	float *gamma,       //γ的值,同α  
	int coeffUsage,   //确定αβγ是用作单个值还是个数组  
	CvSize win,       //每个点用于搜索的最小的领域大小,宽度为奇数  
	CvTermCriteria criteria,   //递归迭代终止的条件准则  
	int scheme)         //确定图像能量场的数据选择,1为灰度,2为灰度梯度  
{
	int i, j, k;
	int neighbors = win.height * win.width;    //当前点领域中点的个数  

											   //当前点的位置  
	int centerx = win.width >> 1;
	int centery = win.height >> 1;

	float invn;        //n 的倒数?  
	int iteration = 0;     //迭代次数  
	int cOnverged= 0;      //收敛标志,0为非收敛  

							//能量  
	float *Econt;    //  
	float *Ecurv;   //轮廓曲线能量  
	float *Eimg;    //图像能量  
	float *E;      //  

				   //αβγ的副本  
	float _alpha, _beta, _gamma;

	/*#ifdef GRAD_SNAKE */
	float *gradient = NULL;
	uchar *map = NULL;
	int map_width = ((roi.width - 1) >> 3) + 1;
	int map_height = ((roi.height - 1) >> 3) + 1;
	//CvSepFilter pX, pY;
#define WTILE_SIZE 8  
#define TILE_SIZE (WTILE_SIZE + 2)         
	short dx[TILE_SIZE*TILE_SIZE], dy[TILE_SIZE*TILE_SIZE];
	CvMat _dx = cvMat(TILE_SIZE, TILE_SIZE, CV_16SC1, dx);
	CvMat _dy = cvMat(TILE_SIZE, TILE_SIZE, CV_16SC1, dy);
	CvMat _src = cvMat(roi.height, roi.width, CV_8UC1, src);

	/* inner buffer of convolution process */
	//char ConvBuffer[400];  

	/*#endif */

	//检点参数的合理性  
	/* check bad arguments */
	//if (src == NULL)
	//	return CV_NULLPTR_ERR;
	//if ((roi.height <= 0) || (roi.width <= 0))
	//	return CV_BADSIZE_ERR;
	//if (srcStep > 1);
			int right = MIN(roi.width - 1 - pt[i].x, win.width >> 1);
			int upper = MIN(pt[i].y, win.height >> 1);
			int bottom = MIN(roi.height - 1 - pt[i].y, win.height >> 1);
			//初始化Econt  
			maxEcOnt= 0;
			minEcOnt= _CV_SNAKE_BIG;
			//在合理的搜索范围内进行Econt的计算  
			for (j = -upper; j <= bottom; j++)
			{
				for (k = -left; k <= right; k++)
				{
					int diffx, diffy;
					float energy;
					//在轮廓点集的首尾相接处作相应处理,求轮廓点差分  
					if (i == 0)
					{
						diffx = pt[n - 1].x - (pt[i].x + k);
						diffy = pt[n - 1].y - (pt[i].y + j);
					}
					else
						//在其他地方作一般处理  

					{
						diffx = pt[i - 1].x - (pt[i].x + k);
						diffy = pt[i - 1].y - (pt[i].y + j);
					}
					//将邻域陈列坐标转成Econt数组的下标序号,计算邻域中每点的Econt  
					//Econt的值等于平均距离和此点和上一点的距离的差的绝对值(这是怎么来的?)  
					Econt[(j + centery) * win.width + k + centerx] = energy =
						(float)fabs(ave_d -
							cvSqrt((float)(diffx * diffx + diffy * diffy)));
					//求出所有邻域点中的Econt的最大值和最小值  
					maxEcOnt= MAX(maxEcont, energy);
					minEcOnt= MIN(minEcont, energy);
				}
			}
			//求出邻域点中最大值和最小值之差,并对所有的邻域点的Econt进行标准归一化,若最大值最小  
			//相等,则邻域中的点Econt全相等,Econt归一化束缚为0  
			tmp = maxEcont - minEcont;
			tmp = (tmp == 0) ? 0 : (1 / tmp);
			for (k = 0; k = criteria.max_iter))
			cOnverged= 1;
		//到大相应精度时,停止迭代(与第一个条件有相同效果)  
		if ((criteria.type & CV_TERMCRIT_EPS) && (moved <= criteria.epsilon))
			cOnverged= 1;
	}

	//释放各个缓冲区  
	cvFree(&Econt);
	cvFree(&Ecurv);
	cvFree(&Eimg);
	cvFree(&E);

	if (scheme == _CV_SNAKE_GRAD)
	{
		cvFree(&gradient);
		cvFree(&map);
	}
	return 1;
}


void cvSnakeImage(const IplImage* src, CvPoint* points,
	int length, float *alpha,
	float *beta, float *gamma,
	int coeffUsage, CvSize win,
	CvTermCriteria criteria, int calcGradient)
{

	CV_FUNCNAME("cvSnakeImage");

	//__BEGIN__;

	uchar *data;
	CvSize size;
	int step;

	//if (src->nChannels != 1)
		//CV_ERROR(CV_BadNumChannels, "input image has more than one channel");

	//if (src->depth != IPL_DEPTH_8U)
		//CV_ERROR(CV_BadDepth, cvUnsupportedFormat);

	cvGetRawData(src, &data, &step, &size);

	icvSnake8uC1R(data, step, size, points, length,
		alpha, beta, gamma, coeffUsage, win, criteria,
		calcGradient ? _CV_SNAKE_GRAD : _CV_SNAKE_IMAGE);
	//__END__;
}

/* end of file */





//测试应用程序

//#include "stdafx.h"  
#include 
  
    #include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         IplImage *image = 0; //原始图像 IplImage *image2 = 0; //原始图像copy using namespace std; int Thresholdness = 41; int ialpha = 20; int ibeta = 20; int igamma = 20; void onChange(int pos) { if (image2) cvReleaseImage(&image2); if (image) cvReleaseImage(&image); image2 = cvLoadImage("E://素材//sfsd.jpg", 1); //显示图片 image = cvLoadImage("E://素材//sfsd.jpg", 0); cvThreshold(image, image, Thresholdness, 205, CV_THRESH_BINARY); //分割域值 CvMemStorage* storage = cvCreateMemStorage(0); CvSeq* cOntours= 0; cvFindContours(image, storage, &contours, sizeof(CvContour), //寻找初始化轮廓 CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); if (!contours) return; int length = contours->total; //cout <
      
     
    
   
  

?
?

图1 ?测试效果图

图2 ?测试原图

本文《图像处理之其他杂项(三)之cvSnakeImage改进升级兼容 适用于opencv2,,在opencv3.0以上版本中测试通过》版权归Coming_is_winter所有,引用图像处理之其他杂项(三)之cvSnakeImage改进升级兼容 适用于opencv2,,在opencv3.0以上版本中测试通过需遵循CC 4.0 BY-SA版权协议。


推荐阅读
  • Python使用Pillow包生成验证码图片的方法
    本文介绍了使用Python中的Pillow包生成验证码图片的方法。通过随机生成数字和符号,并添加干扰象素,生成一幅验证码图片。需要配置好Python环境,并安装Pillow库。代码实现包括导入Pillow包和随机模块,定义随机生成字母、数字和字体颜色的函数。 ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • 也就是|小窗_卷积的特征提取与参数计算
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了卷积的特征提取与参数计算相关的知识,希望对你有一定的参考价值。Dense和Conv2D根本区别在于,Den ... [详细]
  • 基于dlib的人脸68特征点提取(眨眼张嘴检测)python版本
    文章目录引言开发环境和库流程设计张嘴和闭眼的检测引言(1)利用Dlib官方训练好的模型“shape_predictor_68_face_landmarks.dat”进行68个点标定 ... [详细]
  • 微软评估和规划(MAP)的工具包介绍及应用实验手册
    本文介绍了微软评估和规划(MAP)的工具包,该工具包是一个无代理工具,旨在简化和精简通过网络范围内的自动发现和评估IT基础设施在多个方案规划进程。工具包支持库存和使用用于SQL Server和Windows Server迁移评估,以及评估服务器的信息最广泛使用微软的技术。此外,工具包还提供了服务器虚拟化方案,以帮助识别未被充分利用的资源和硬件需要成功巩固服务器使用微软的Hyper - V技术规格。 ... [详细]
  • node.jsrequire和ES6导入导出的区别原 ... [详细]
  • 如何使用Python从工程图图像中提取底部的方法?
    本文介绍了使用Python从工程图图像中提取底部的方法。首先将输入图片转换为灰度图像,并进行高斯模糊和阈值处理。然后通过填充潜在的轮廓以及使用轮廓逼近和矩形核进行过滤,去除非矩形轮廓。最后通过查找轮廓并使用轮廓近似、宽高比和轮廓区域进行过滤,隔离所需的底部轮廓,并使用Numpy切片提取底部模板部分。 ... [详细]
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • Python瓦片图下载、合并、绘图、标记的代码示例
    本文提供了Python瓦片图下载、合并、绘图、标记的代码示例,包括下载代码、多线程下载、图像处理等功能。通过参考geoserver,使用PIL、cv2、numpy、gdal、osr等库实现了瓦片图的下载、合并、绘图和标记功能。代码示例详细介绍了各个功能的实现方法,供读者参考使用。 ... [详细]
  • MATLAB函数重名问题解决方法及数据导入导出操作详解
    本文介绍了解决MATLAB函数重名的方法,并详细讲解了数据导入和导出的操作。包括使用菜单导入数据、在工作区直接新建变量、粘贴数据到.m文件或.txt文件并用load命令调用、使用save命令导出数据等方法。同时还介绍了使用dlmread函数调用数据的方法。通过本文的内容,读者可以更好地处理MATLAB中的函数重名问题,并掌握数据导入导出的各种操作。 ... [详细]
  • Android自定义控件绘图篇之Paint函数大汇总
    本文介绍了Android自定义控件绘图篇中的Paint函数大汇总,包括重置画笔、设置颜色、设置透明度、设置样式、设置宽度、设置抗锯齿等功能。通过学习这些函数,可以更好地掌握Paint的用法。 ... [详细]
  • 本文介绍了Python语言程序设计中文件和数据格式化的操作,包括使用np.savetext保存文本文件,对文本文件和二进制文件进行统一的操作步骤,以及使用Numpy模块进行数据可视化编程的指南。同时还提供了一些关于Python的测试题。 ... [详细]
  • 大数据Hadoop生态(20)MapReduce框架原理OutputFormat的开发笔记
    本文介绍了大数据Hadoop生态(20)MapReduce框架原理OutputFormat的开发笔记,包括outputFormat接口实现类、自定义outputFormat步骤和案例。案例中将包含nty的日志输出到nty.log文件,其他日志输出到other.log文件。同时提供了一些相关网址供参考。 ... [详细]
  • 本文讨论了在shiro java配置中加入Shiro listener后启动失败的问题。作者引入了一系列jar包,并在web.xml中配置了相关内容,但启动后却无法正常运行。文章提供了具体引入的jar包和web.xml的配置内容,并指出可能的错误原因。该问题可能与jar包版本不兼容、web.xml配置错误等有关。 ... [详细]
author-avatar
QEWERTGF_978
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有