affine modle

// tttt.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "opencv/cv.h"
#include "opencv/highgui.h"

int _tmain(int argc, _TCHAR* argv[])
{
	IplImage *img1 = cvLoadImage("0.bmp",0);
	IplImage *img2 = cvLoadImage("1.bmp",0);
	IplImage *diff = cvCreateImage(cvGetSize(img1),8,1);
	cvSub(img1,img2,diff);
// 	cvScale(diff,diff,10);
	CvScalar err = cvSum(diff);
	cvShowImage("tewt",diff);
	CvMat *mat = cvCreateMat(6,1,CV_32FC1);
	int _grad[4];
	int _x[12];
	int _a[36];
	int _b[6];
	CvMat grad = cvMat(2,2,CV_32SC1,_grad);
	CvMat X = cvMat(6,2,CV_32SC1,_x);
	CvMat *tmp = cvCreateMat(6,2,CV_32SC1);
	CvMat A = cvMat(6,6,CV_32SC1,_a);
	CvMat B = cvMat(6,1,CV_32SC1,_b);
	cvSetZero(&A);
	cvSetZero(&B);

	uchar *p1 = img1->imageData+img1->widthStep;
	uchar *p2 = img2->imageData+img2->widthStep;
	for (int  i = 1 ; i < img1->height - 1 ; i++ , p1+=img1->widthStep , p2+=img2->widthStep)
	{
		for (int j = 1 ; j < img1->width - 1 ; j++)
		{

		}
	}

	cvWaitKey(0);
	return 0;
}

* This example shows how to use shape-based matching * in order to find a model region and use it for * further tasks. * Here, the additional task consists of reading text * within a certain region, wherefore the image has * to be aliged using the matching transformation. * * Initialization. dev_update_window ('off') dev_close_window () * Initialize visualization. read_image (ReferenceImage, 'board/board_01') get_image_size (ReferenceImage, Width, Height) initialize_visualization (Width / 2, Height / 2, WindowHandle, WindowHandleText) disp_continue_message (WindowHandle, 'black', 'true') disp_description_text (WindowHandleText) * * Define ROIs: * ROI for the shape model. dev_set_window (WindowHandle) dev_display (ReferenceImage) gen_rectangle1 (ROIModel, 60, 535, 185, 900) dev_display (ROIModel) * ROI for the text. gen_rectangle1 (ROIText, 445, 585, 590, 765) dev_display (ROIText) disp_model_message (WindowHandle) stop () * * Prepare the shape-based matching model. reduce_domain (ReferenceImage, ROIModel, ModelImage) * Create shape model and set parameters (offline step). create_generic_shape_model (ModelHandle) * Train the shape model. train_generic_shape_model (ModelImage, ModelHandle) * * Prepare the text model. create_text_model_reader ('auto', 'Industrial_0-9A-Z_Rej.omc', TextModel) * * We look for the reference transformation which we will need * for the alignment. We can extract it by finding the instance * on the reference image. * Set find parameters. set_generic_shape_model_param (ModelHandle, 'num_matches', 1) set_generic_shape_model_param (ModelHandle, 'min_score', 0.5) find_generic_shape_model (ReferenceImage, ModelHandle, MatchResultID, Matches) get_generic_shape_model_result (MatchResultID, 'all', 'hom_mat_2d', HomMat2DModel) * * Find the object in other images (online step). for i := 1 to 9 by 1 read_image (SearchImage, 'board/board_' + i$'02') find_generic_shape_model (SearchImage, ModelHandle, MatchResultID, Matches) get_generic_shape_model_result (MatchResultID, 'all', 'hom_mat_2d', HomMat2DMatch) * Compute the transformation matrix. hom_mat2d_invert (HomMat2DMatch, HomMat2DMatchInvert) hom_mat2d_compose (HomMat2DModel, HomMat2DMatchInvert, TransformationMatrix) affine_trans_image (SearchImage, ImageAffineTrans, TransformationMatrix, 'constant', 'false') * * Visualization. dev_set_window (WindowHandle) dev_display (SearchImage) get_generic_shape_model_result_object (InstanceObject, MatchResultID, 'all', 'contours') dev_display (InstanceObject) * * Reading text and numbers on the aligned image. reduce_domain (ImageAffineTrans, ROIText, ImageOCR) find_text (ImageOCR, TextModel, TextResultID) get_text_object (Characters, TextResultID, 'all_lines') get_text_result (TextResultID, 'class', RecognizedText) * * Visualization. dev_set_window (WindowHandleText) dev_display (ImageAffineTrans) dev_set_colored (12) dev_display (Characters) disp_finding_text (Characters, WindowHandle, WindowHandleText, RecognizedText) wait_seconds (0.5) endfor disp_end_of_program_message (WindowHandle, 'black', 'true') stop () dev_close_window ()
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值