图片像素对比OpenCV实现,实现人工分割跟算法分割图像结果的对比
来源:互联网 发布:淘宝卖家流量中心 编辑:程序博客网 时间:2024/05/17 06:55
图片对比,计算不同像素个数,已经比率。实现人工分割跟算法分割图像结果的对比,但是只能用灰度图像作为输入
// imageMaskComparison.cpp : 定义控制台应用程序的入口点。//// imageMaskComparison.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>#include <iostream>using namespace std;using namespace cv;int main(){String image_name,image1,image2;cout<<"input Parameters:"<<endl;cout<<"image name 1 : ";cin>>image1;cout<<"image name 2 : ";cin>>image2;Mat img1 = imread((char *)image1.c_str(), CV_LOAD_IMAGE_GRAYSCALE);Mat img2 = imread((char *)image2.c_str(), CV_LOAD_IMAGE_GRAYSCALE);//两幅图像的大小需要一致 imshow("img1",img1);imshow("img2",img2);Mat img_result1 , img_result2 , img_result ;img_result1.create(img1.rows,img1.cols,CV_8UC1);img_result1 = 255;img_result2.create(2,img1.size,CV_8UC1);img_result2 = 255;img_result.create(img2.rows,img2.cols,CV_8UC1);img_result = 0;//subtract(img1,img2, img_result1);//subtract(img2,img1, img_result2);//add(img_result1, img_result2, img_result1);absdiff(img1,img2,img_result);int init_index = 0;/*for(int i=0; i<img_result.rows; i++){for(int j=0; j<img_result.cols; j++) {if (img_result.at<uchar>(i,j)== 255){init_index++;}}}*/int count = 0;for(int i=0; i<img1.rows; i++){for(int j=0; j<img1.cols; j++) {if ( img1.at<uchar>(i,j) == img2.at<uchar>(i,j)){img_result.at<uchar>(i,j) = (uchar)255;}else{count++;img_result.at<uchar>(i,j) = (uchar)0;}}}int sum = img1.cols*img1.rows;double error_ratio = count/(double)sum;//cout<<init_index<<endl;cout<<"number of different pixel:"<<count<<endl;cout<<"error ratio: "<<error_ratio<<endl;imwrite("result.bmp",img_result);//imshow("result1", img_result1);//imshow("result2", img_result2); namedWindow( "result", CV_WINDOW_AUTOSIZE );imshow("result", img_result);waitKey();return 0;}
0 0
- 图片像素对比OpenCV实现,实现人工分割跟算法分割图像结果的对比
- 利用OpenCV实现图像的阈值分割
- POSTGRESQL 与MYSQL 实现分割字符串的方法对比
- opencv之金字塔实现图像分割
- opencv之分水岭实现图像分割
- opencv用金字塔cvPyrSegmentation实现图像分割
- OpenCV学习 kmeans实现图像分割
- 基于GraphCuts图割算法的图像分割----OpenCV代码与实现
- 分水岭算法分割图像的原理概述及OpenCV代码实现
- 基于GraphCuts图割算法的图像分割----OpenCV代码与实现
- Android 使用OPENCV实现图像实时对比
- matlab粒子群算法结合模糊聚类分割算法实现图像的分割
- 用分水岭算法实现图像分割 (祝勇)
- 图像分割-区域标记算法(实现)
- matlab实现分水岭算法处理图像分割
- 5.5用分水岭算法实现图像分割
- 图像分割基础算法及实现实例
- java代码 kmeans算法实现 图像分割
- 获取路由器超级用户权限(你懂得...)
- Maximum Subarray
- 实现一个计算器
- HDU - 5012 Dice(BFS)
- python的优先权队列
- 图片像素对比OpenCV实现,实现人工分割跟算法分割图像结果的对比
- 图的深度遍历(DFS)
- 纪念逝去的昨天(1)
- Java学习笔记之Java基础
- html中input文本框,初始里边有文字提示,当点击时,文字消失
- 公司笔试题——统计10进制数中的二进制值有多少个1
- Vistual studio 快捷键积累
- 程序崩溃---autorelease异常
- 毕业两年,博客一年,时光