热门标签 | 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版权协议。


推荐阅读
  • 本文介绍了在CentOS上安装Python2.7.2的详细步骤,包括下载、解压、编译和安装等操作。同时提供了一些注意事项,以及测试安装是否成功的方法。 ... [详细]
  • 本文介绍了C++中省略号类型和参数个数不确定函数参数的使用方法,并提供了一个范例。通过宏定义的方式,可以方便地处理不定参数的情况。文章中给出了具体的代码实现,并对代码进行了解释和说明。这对于需要处理不定参数的情况的程序员来说,是一个很有用的参考资料。 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • PHP图片截取方法及应用实例
    本文介绍了使用PHP动态切割JPEG图片的方法,并提供了应用实例,包括截取视频图、提取文章内容中的图片地址、裁切图片等问题。详细介绍了相关的PHP函数和参数的使用,以及图片切割的具体步骤。同时,还提供了一些注意事项和优化建议。通过本文的学习,读者可以掌握PHP图片截取的技巧,实现自己的需求。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 成功安装Sabayon Linux在thinkpad X60上的经验分享
    本文分享了作者在国庆期间在thinkpad X60上成功安装Sabayon Linux的经验。通过修改CHOST和执行emerge命令,作者顺利完成了安装过程。Sabayon Linux是一个基于Gentoo Linux的发行版,可以将电脑快速转变为一个功能强大的系统。除了作为一个live DVD使用外,Sabayon Linux还可以被安装在硬盘上,方便用户使用。 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 本文介绍了在mac环境下使用nginx配置nodejs代理服务器的步骤,包括安装nginx、创建目录和文件、配置代理的域名和日志记录等。 ... [详细]
  • Redis底层数据结构之压缩列表的介绍及实现原理
    本文介绍了Redis底层数据结构之压缩列表的概念、实现原理以及使用场景。压缩列表是Redis为了节约内存而开发的一种顺序数据结构,由特殊编码的连续内存块组成。文章详细解释了压缩列表的构成和各个属性的含义,以及如何通过指针来计算表尾节点的地址。压缩列表适用于列表键和哈希键中只包含少量小整数值和短字符串的情况。通过使用压缩列表,可以有效减少内存占用,提升Redis的性能。 ... [详细]
  • 本文介绍了深入浅出Linux设备驱动编程的重要性,以及两种加载和删除Linux内核模块的方法。通过一个内核模块的例子,展示了模块的编译和加载过程,并讨论了模块对内核大小的控制。深入理解Linux设备驱动编程对于开发者来说非常重要。 ... [详细]
  • Imtryingtofigureoutawaytogeneratetorrentfilesfromabucket,usingtheAWSSDKforGo.我正 ... [详细]
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社区 版权所有