Install and build OpenCV python From Source on Raspberry pi 4 and 3

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 เม.ย. 2021
  • In this video you will learn how to install opencv for python in raspberry pi with two different methods, so if you start using raspberry pi and want to use opencv on your projects watch this video.
    ------------------------------------------------------------------------
    The raspberry pi used in this video:
    Raspberry Pi 4 Model B 4GB
    -------------------------------------------------------------------------
    OpenCV documentation:
    docs.opencv.org/master/d2/de6...
    -------------------------------------------------------------------------
    Download opencv source:
    git clone github.com/opencv/opencv.git
    -------------------------------------------------------------------------
    OpenCV-Python from Pre-built Binaries:
    sudo apt-get install python3-opencv
    -------------------------------------------------------------------------
    Dependencies for building OpenCV from source:
    sudo apt-get install cmake
    sudo apt-get install gcc g++
    sudo apt-get install python3-dev python3-numpy
    sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
    sudo apt-get install libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
    sudo apt-get install libgtk2.0-dev
    sudo apt-get install libgtk-3-dev
    -------------------------------------------------------------------------
    Please LIKE and SUBSCRIBE for more content and supporting!
    #opencv#raspberrypi

ความคิดเห็น • 80

  • @index-zero
    @index-zero  2 ปีที่แล้ว +11

    OBS: for those who are getting error: No module named 'cv2'
    I think it's because there is no python2 installed anymore in raspberry pi, therefore opencv will not be installed properly.
    Solution:
    After you run sudo make install run this command: sudo cp -R /usr/local/lib/python3.9/site-packages/cv2/ /usr/local/lib/python3.9/dist-packages/
    Just check if you have the same python version otherwise just change it to your pythons version so for example if you have python3.7 installed change the python3.9 to python3.7.
    Let me know if this solve your problem.

    • @SunilKumar-qo2nb
      @SunilKumar-qo2nb 2 ปีที่แล้ว +1

      cp: cannot stat '/usr/local/lib/python3.7/site-packages/cv2/': No such file or directory
      after running the command sudo -R/usr.. I am getting this error
      I am not able to creat cv2 folder manually also in the path : /usr/local/lib/python3.7/site-packages (getting message as permission denied)
      Please reply

    • @index-zero
      @index-zero  2 ปีที่แล้ว +2

      @@SunilKumar-qo2nbrun this commend after you did everything in this video and if still there is not any folder called cv2 in /usr/local/lib/python3.7/site-packages so that means the opencv was not installed correctly and it can have many reason so I dont really know how to solve it. Otherwise you can install it from Pre-built Binaries by typing 'sudo apt-get install python3-opencv'.

    • @danifrii
      @danifrii 2 ปีที่แล้ว +1

      worked for me. Thank you

    • @040danukurnia8
      @040danukurnia8 2 ปีที่แล้ว +1

      its work

    • @boramawi
      @boramawi ปีที่แล้ว

      That worked for me! Thanks Cheers! :)

  • @priyagujre3113
    @priyagujre3113 ปีที่แล้ว +1

    Thank you!
    The compile process got stuck many times . It took more than 18hours for opencv to get installed( Rpi3b+, 1gb ram)
    I increased the swapsize to 4096.
    Kept GPU at 76. I used make -j4 command.
    Made sure that the board is well ventilated and not getting heated up.
    Also I used raspcontroller app to check if the download is still continuing or got stuck .
    I don't know if this makes sense, but it helped me.
    After 99% it took almost three hours to get the process completed.

  • @tranthanh-wx5ps
    @tranthanh-wx5ps 2 ปีที่แล้ว +1

    thank you very much!

  • @imadeddarraz3247
    @imadeddarraz3247 3 ปีที่แล้ว +1

    thank you so much...

  • @mayorjed4719
    @mayorjed4719 2 ปีที่แล้ว +1

    Thank you!

  • @oliverorwell3773
    @oliverorwell3773 2 ปีที่แล้ว +1

    Great video ❤❤

  • @Ber-rs6mq
    @Ber-rs6mq 7 หลายเดือนก่อน

    Thank you very much

  • @noureddineel-haryqy4941
    @noureddineel-haryqy4941 2 ปีที่แล้ว +1

    thank you

  • @qzorn4440
    @qzorn4440 ปีที่แล้ว

    really wonderful OpenCV video. Would the installation be the same for an Orange Pi 800? Thank you.

  • @truongvu9370
    @truongvu9370 3 ปีที่แล้ว +1

    thanks you, i did yet

  • @PatrickBateman32
    @PatrickBateman32 9 หลายเดือนก่อน +3

    Yo please help out at 63% it canceled and gave a long list of errors and whatnots but the main thing is [makefile:182: all] Error 2. Ive tried redoing the make command and that pip upgrade thing you said

  • @oliverorwell3773
    @oliverorwell3773 2 ปีที่แล้ว +1

    I want to know how to install cvzone and tensorflow 2 on raspberry pi

  • @gowtham-qj7qg
    @gowtham-qj7qg 3 ปีที่แล้ว +3

    it took 4 hours for me in pi 4

  • @wassimmodric6436
    @wassimmodric6436 4 หลายเดือนก่อน

    Is the raspberry pi 3 work good with openCV or i need to buy tje raspberry pi 4 ?

  • @bgmistreamersmoments1835
    @bgmistreamersmoments1835 ปีที่แล้ว

    i am getting error in make command that no target is sepcified and no makefile found

  • @vnpoka3020
    @vnpoka3020 3 ปีที่แล้ว +3

    thank you very much. but i spent 7 hours to install it. this is very long long time. it is not 2 3 hours . lmao

  • @mrmoody915
    @mrmoody915 3 ปีที่แล้ว +1

    I keep getting cannot create directory 'build': File exists every time I input "cd ~opencv && mkdir build && cd build"

    • @index-zero
      @index-zero  3 ปีที่แล้ว

      Sounds like you already created a build folder so just type 'cd opencv/build'.

  • @badarali6550
    @badarali6550 2 ปีที่แล้ว +4

    Can it be install in Raspberry Pi 3 model B ram 1GB?

  • @Vector-uz9sc
    @Vector-uz9sc 3 ปีที่แล้ว +2

    can i do the same for the raspberry pi zero w?

    • @index-zero
      @index-zero  3 ปีที่แล้ว +1

      Yeh I think it should work.

    • @sravanjosh1218
      @sravanjosh1218 2 ปีที่แล้ว

      @Vector5284 had it worked with rasp pi Zero W ?

  • @ilaydabalk8355
    @ilaydabalk8355 2 ปีที่แล้ว +3

    Hello everyone, firstly thank you for your explanatory video. I've a problem about installation of openCV to my raspberry pi 4 model - b,
    Problems that program gave me :
    make[2]: *** [modules/dnn/CMakeFiles/opencv_perf_dnn.dir/build.make:230: bin/opencv_perf_dnn] Error 1
    make[1]: *** [CMakeFiles/Makefile2:2238: modules/dnn/CMakeFiles/opencv_perf_dnn.dir/all] Error 2
    make: *** [Makefile:182: all] Error 2
    Are there anybody who have an idea to fix that problem, thanx

    • @amritraj7640
      @amritraj7640 2 ปีที่แล้ว

      Run that code again to fix. Same problem but worked for me

    • @Protias12
      @Protias12 11 หลายเดือนก่อน

      @@amritraj7640 I have run "make" again but the problem persists, do you have any other alternative solution?

  • @SunilKumar-qo2nb
    @SunilKumar-qo2nb 2 ปีที่แล้ว +3

    Hello sir.. I am also getting the same error i.e.
    python3
    import cv2 as cv
    ModuleNot FoundError: No module named 'cv2'
    I followed exactly the same steps as mentioned in your doc. Please help as soon as possible.
    I am using Raspberry Pi 4 Model B 8GB

  • @syakirpro1929
    @syakirpro1929 3 ปีที่แล้ว +2

    Sir I have a question, I follow every step and it seems to be okey however. At 99% of /Desktop/opencv/build/ $ make , my desktop totally freeze. Hope you can help me sir thank you

    • @index-zero
      @index-zero  3 ปีที่แล้ว +1

      Sorry but I really don't know what is the problem :-( .

    • @syakirpro1929
      @syakirpro1929 3 ปีที่แล้ว +1

      Is okey sir thank you hehe

    • @daBAAAAM
      @daBAAAAM 2 ปีที่แล้ว

      @@syakirpro1929 Did you fix the problem? I have the same one

  • @fasel991
    @fasel991 ปีที่แล้ว +1

    When i write cmake ../ i got ( command not found) what is the solution please?

    • @hursitsahin864
      @hursitsahin864 ปีที่แล้ว

      did you get any answer?

    • @arindamchakraborty9520
      @arindamchakraborty9520 ปีที่แล้ว

      check if you are creating the folder ("Build") inside the opencv directory or not
      if not:
      $ cd opencv
      $ mkdir Build
      $ cd Build
      $ cmake ../

  • @solouniverse5252
    @solouniverse5252 3 ปีที่แล้ว +2

    Open CV 4 in raspberry Pi is that same method???
    Please reply

  • @roni1422
    @roni1422 2 ปีที่แล้ว +1

    "make" operation takes a lot of time.It's about 44 percent and it started 12 hours ago. what i suposed to do?

    • @index-zero
      @index-zero  2 ปีที่แล้ว

      Try "make -j4", it will speed up the make process.

    • @roni1422
      @roni1422 2 ปีที่แล้ว

      @@index-zero I tried, now the make operation does not work. it wtirtes" no targets specified and no makefile found" and "command not found" . can you help me?

    • @roni1422
      @roni1422 2 ปีที่แล้ว

      @@index-zero I tried, now the make operation does not work. it wtirtes" no targets specified and no makefile found" and "command not found" . can you help me?

    • @index-zero
      @index-zero  2 ปีที่แล้ว +1

      @@roni1422 you have to run this command when you are in build folder, so when you are in opencv folder run cd build then run the make -j4

    • @roni1422
      @roni1422 2 ปีที่แล้ว +1

      @@index-zero The raspberry stucks at 90% when I use make-j4. do you know what can I do?

  • @yunusemrekoksal9481
    @yunusemrekoksal9481 2 ปีที่แล้ว +1

    i am getting this error how can i fix it
    (bash: cd: too many arguments)

    • @index-zero
      @index-zero  2 ปีที่แล้ว +1

      When you are getting this error?

    • @yunusemrekoksal9481
      @yunusemrekoksal9481 2 ปีที่แล้ว +1

      @@index-zero mkdir build

    • @index-zero
      @index-zero  2 ปีที่แล้ว

      Sorry I'm not sure why you are getting this error.

  • @firmanagroni2012
    @firmanagroni2012 ปีที่แล้ว +1

    why when in "make" it stops at 98 percent only

    • @mohalghaithi9873
      @mohalghaithi9873 ปีที่แล้ว

      did u find a solution, I'm having the same problem

    • @Anor27
      @Anor27 ปีที่แล้ว

      @@mohalghaithi9873 me too

    • @Sniper-rl3xq
      @Sniper-rl3xq ปีที่แล้ว

      same afterv almost 11 hours

    • @gero29663
      @gero29663 11 หลายเดือนก่อน

      me too, any solution?

  • @siddharamdivate9710
    @siddharamdivate9710 2 ปีที่แล้ว +1

    Hey, I have installed opencv on my raspberry pi 3 , i can import opencv in terminal only but not in thonny python, if i try to run command import cv2 in thonny python, i'm getting this error " No module named cv2 " ,
    Please help me resolve this problem

    • @index-zero
      @index-zero  2 ปีที่แล้ว

      I have tried in my raspberry pi 4 and it works just fine so I dont know what is exactly the problem.

  • @zAbdullahKhan
    @zAbdullahKhan 3 ปีที่แล้ว +3

    Please always mention Raspberry Pi specs. I know it is Pi 4, but the memory is really a big concern when it comes to compiling and installing opencv, that is, if your Pi has low memory i.e. 2GB the chances are that it will freeze at some point and won't be able to install opencv eventually. BTW, what are your specs? Also, what version of Raspbian have you installed 32-bit or 64bit?

    • @index-zero
      @index-zero  3 ปีที่แล้ว +1

      Yeh you are right I had to mention it thank that you pointed it out.
      I have a Raspberry Pi 4 - 4GB, and also have installed a 32-bit Raspbian.

    • @tariqnajjar6589
      @tariqnajjar6589 ปีที่แล้ว

      the documentation says that it is for ubuntu .... 64bit
      how did it work with you with 32 bit?

  • @pipe4x
    @pipe4x 2 ปีที่แล้ว +1

    I ´ve follow all the steps along with the video and I keep getting an error in the las step, when you go to python to check the installation :
    python3
    import cv2 as cv
    ModuleNot FoundError: No module named 'cv2'
    do you know what is the problem? I am trying to instal in a raspberry pi3 model B+

    • @index-zero
      @index-zero  2 ปีที่แล้ว

      Did you install with sudo?

    • @JiaEnLimmmm
      @JiaEnLimmmm 2 ปีที่แล้ว

      Hi same issue as well! After sudo make install, i went to check it mention similar error as well

    • @JiaEnLimmmm
      @JiaEnLimmmm 2 ปีที่แล้ว

      Somehow issue is resolved when i ran sudo apt-get install python3-opencv

  • @user-pg1hs2fp3z
    @user-pg1hs2fp3z 2 ปีที่แล้ว +2

    When I tape import cv2,I get this error
    RuntimeError: module compiled against API version 0xf but this version of numpy is 0xd
    Traceback (most recent call last):
    File "", line 1, in
    File "/home/pi/.local/lib/python3.9/site-packages/cv2/__init__.py", line 8, in
    from .cv2 import *
    ImportError: numpy.core.multiarray failed to import
    how I can fix it

    • @index-zero
      @index-zero  2 ปีที่แล้ว

      Did you run this command 'sudo apt-get install python3-dev python3-numpy'? Also try this command "pip install numpy --upgrade"

    • @reefstarnes839
      @reefstarnes839 2 ปีที่แล้ว

      @@index-zero I love you

    • @abdulrahmanalkubidh411
      @abdulrahmanalkubidh411 ปีที่แล้ว

      I did it in the terminal and worked for me but when i do it in thonny i still have the same problem pls help and reply

  • @manhhuynhquoc8349
    @manhhuynhquoc8349 ปีที่แล้ว +1

    What OS are you using?

    • @index-zero
      @index-zero  ปีที่แล้ว

      Windows

    • @toongvang1730
      @toongvang1730 ปีที่แล้ว

      ​@@index-zero Do you use raspberry Pi OS Lite(Legacy) or raspberry Pi OS (Legacy)?

  • @jarifmizi2949
    @jarifmizi2949 2 ปีที่แล้ว +1

    I followed all of the instructions as it is .. but still to not working

    • @index-zero
      @index-zero  2 ปีที่แล้ว +1

      Did you try this:
      After you run sudo make install run this command: sudo cp -R /usr/local/lib/python3.9/site-packages/cv2/ /usr/local/lib/python3.9/dist-packages/
      Just check if you have the same python version otherwise just change it to your pythons version so for example if you have python3.7 installed change the python3.9 to python3.7.

  • @EverydayWithNabil
    @EverydayWithNabil 2 ปีที่แล้ว +1

    successfully install in raspbarian os