计算两幅图片的farneback 稠密光流,并将结果图显示出来的程序
2014-07-29 10:25
351 查看
import cv2 import numpy as np import Image import cv2.cv as cv def image_joint(image_list,opt):#opt= vertical ,horizon image_num=len(image_list) image_size=image_list[0].size height=image_size[1] width=image_size[0] if opt=='vertical': new_img=Image.new('RGB',(width,image_num*height),255) else: new_img=Image.new('RGB',(image_num*width,height),255) x=y=0 count=0 for img in image_list: new_img.paste(img,(x,y)) count+=1 if opt=='horizontal': x+=width else : y+=height return new_img start_img = Image.open("C:/Users/Dell/Desktop/output/0260.bmp") later_img = Image.open("C:/Users/Dell/Desktop/output/0275.bmp") print type(start_img) start_img=np.array(start_img) later_img=np.array(later_img) print start_img.shape prvs = cv2.cvtColor(start_img,cv2.COLOR_BGR2GRAY) next = cv2.cvtColor(later_img,cv2.COLOR_BGR2GRAY) print next.shape flow = cv2.calcOpticalFlowFarneback(prvs,next,0.5, 3, 15,3, 5, 1.2, 0) hsv = np.zeros_like(start_img) hsv[...,1] =255 mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1]) hsv[...,0] = ang*180/np.pi/2 hsv[...,2] = cv2.normalize(mag,None,0,255,cv2.NORM_MINMAX) RGB= cv2.cvtColor(hsv,cv2.COLOR_HSV2BGR) GRAY = cv2.cvtColor(RGB,cv2.COLOR_BGR2GRAY) print type(GRAY) GRAY=Image.fromarray(GRAY) start_img=Image.fromarray(start_img) later_img=Image.fromarray(later_img) joint_image=image_joint([start_img,later_img,GRAY],'vertical') joint_image.show() #GRAY.show() #cv2.imshow('frame2',RGB) cv.WaitKey() #if ord('s'): # cv2.imwrite('opticalhsv.png',GRAY)
相关文章推荐
- 射击运动员10 发打中90环有多少种可能,请编写程序计算出来,并打印出结果, 0 环和10环均有效。
- cocostudio显示位置结果和程序加载出来的不一样
- 我一个图片怎么都显示不出来,是博客程序原因还是其他?
- Gtk对于通常的gui程序,大家想做的事就是做一点事件处理(包括各种计算、文件操作等),然后在界面上显示出来
- Farneback 稠密光流--求两幅图像之间的光流--代码(本人略有修改)
- 小程序图片加载不出来(显示)
- c#的一个函数调用程序(怎样让用文本框输入m和n,结果用一个文本框(或列表框)显示出来。)
- python 笔记 在windows下的程序 获取图片并显示出来
- pl/sql developer 程序编译后的结果没有显示出来
- 关于“在MFC对话框程序中图片显示不出来”问题的解决方法
- 输出1/3-3/5+5/7-7/9```+19/21结果 我图片显示不出来了!!!大家帮一下忙呀!
- acmore|acmore.cc1006编写程序,显示计算的结果1007可以使用以下公式计算1008转换温度1009计算圆柱体的体积1010将英尺转换为米
- 编写一个程序,用户输入两个数,求其加减乘除,并用消息框显示计算结果。
- 程序计算结果的指数显示(即科学计数法)
- 编写一个程序,要求用户输入下限整数和一个上限整数,然后,依次计算从下限到上限的每一个整数的平方的加和,最后显示结果
- acmore|acmore.cc1005编写程序,显示计算结果
- 使用asp.net将图片上传并存入SqlServer中,然后从SqlServer中读取并显示出来
- 投票结果的图片进度条显示
- 自定义HTTP处理程序显示图片(asp.net 2.0)
- 如何在搜索结果出来之前,让页面显示“等待中。。。”