Displayed images of videos using OpenCV are strange

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Displayed images of videos using OpenCV are strange

2,462件の閲覧回数
taiki_kasamatsu
Contributor I

I am now using the IMX8QXP-CPU Board (rev. c0) to load videos with OpenCV and simply display them.


When I load the video with cv2.VideoCapture, the size of the image is loaded correctly, but when I display it with imshow, the display is strange as shown in the attached image.

here is my code (I didn't quite understand how to make it a code block, sorry.)

import cv2

#load movie
cap = cv2.VideoCapture('RiverDance.mp4')

while True :
    ret, img = cap.read()
    height, width, channels = img.shape[:3]
    print("width: " + str(width))
    print("height: " + str(height))

    cv2.imshow('Video', img)
    k = cv2.waitKey(1)
    if k==27: # Esc key to stop
        break

I also performed image processing methods such as importing still images, displaying the imported images, exporting, grayscale conversion, Gaussian smoothing, and binarization.
It worked without any problems.

---Types of videos I've tried :

mp4, width:1280, height: 720, 59.94 fps
mp4, width:640, height: 360, 29.97 fps

mp4, width:480, height: 272, 24.0 fps

The same result was obtained for avi, mov, and mkv.

--- about OS info :

ID="fsl-imx-xwayland"
NAME="NXP i.MX Release Distro"
VERSION="4.14-sumo (sumo)"
VERSION_ID="4.14-sumo"
PRETTY_NAME="NXP i.MX Release Distro 4.14-sumo (sumo)"

--- about Python & OpenCV :

Python 3.5.5 (didn't use any virtualenv include pyenv)
[GCC 7.3.0] on linux
>>> import cv2
>>> cv2.__version__
'4.0.1'

Can anyone tell me what causes this and what the solution is?
I'm sorry to bother you, but I would appreciate your help.

thanks in advance.

0 件の賞賛
10 返答(返信)

2,408件の閲覧回数
Anonymous
適用対象外

ha taiki,

try this:

import cv2
import numpy as np

#load movie
cap = cv2.VideoCapture(0)

while True :
ret, img = cap.read()
height, width, channels = img.shape[:3]
print("width: " + str(width))
print("height: " + str(height))

cv2.imshow('Video', img)
k = cv2.waitKey(1)
if k==27: # Esc key to stop
break

thanks

Kalaimani Arumugam

0 件の賞賛

2,399件の閲覧回数
taiki_kasamatsu
Contributor I

Thank you for your answer!


From the looks of it, the python source you gave me is to imshow the input image from the camera, right?In this case, there is no problem when the input is from the camera, but when the input is from a video file such as mp4, a strange image like the one attached is displayed.

0 件の賞賛

2,386件の閲覧回数
Anonymous
適用対象外

hai taiki,

   I am generating the issue here for fix. i need some check operation done there

1.Is it work with normal web camera application.

cap = cv2.VideoCapture(0)  

 2. Also check the image operation in imshow.

cap = cv2.imread('''Image Location''')

Thanks

kalaimani Arumugam 

0 件の賞賛

2,380件の閲覧回数
taiki_kasamatsu
Contributor I

hi kalaimani,

1. Yes, This works with no problems. I can show the image from some cameras properly.

cap = cv2.VideoCapture(0)  

 

2. This is also working and I can get it's sizes and show properly

cap = cv2.imread('''Image Location''')

 

Thank you.

0 件の賞賛

2,376件の閲覧回数
Anonymous
適用対象外

 hai taiki, 

   Till now i am not getting this issue. Try to Uninstall and install the "openCV" 

 

Thanks

Kalaimani Arumugam

 

 

0 件の賞賛

2,366件の閲覧回数
taiki_kasamatsu
Contributor I

kalaimani

Thank you for trying.
I'll try some things here as well.

Thanks!

0 件の賞賛

2,450件の閲覧回数
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello taiki,

 

You should use the Linux 5.4.70_2.3.0​ for python 4. I just the same procedure on my pc with the same result, but If i change for python 4 it pass, so please try it.

 

Regards

 

0 件の賞賛

2,414件の閲覧回数
taiki_kasamatsu
Contributor I

Thank you for your answer.
After that I did some research and it seems that python4 doesn't exist yet, which version of python4 are you referring to?

0 件の賞賛

2,348件の閲覧回数
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello,

 

Sorry there is no python 4, the latest version is python 3.9.

 

Regards

 

0 件の賞賛

2,327件の閲覧回数
takayuki_ishii
Contributor IV

Hello @Bio_TICFSL 

I have same problem on i.MX8QXP MEK + Linux BSP L5.4.70_2.3.0.

So please teach me which method do you use to install python3.9 to Linux BSP L5.4.70_2.3.0?

 1) Add package of python3.9 to local.conf and bitbake

 2) Download python3.9 source code and configure/make/make install it.

 3) Some other method like "pip update"

 

I look forward to hearing from you.

 

Best regards,

Ishii.

0 件の賞賛