The program that calculates the farneback dense light flow of two pictures and shows the result graph

Source: Internet
Author: User
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] I F 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 star t_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), Flo w[...,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)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.