New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Python and cv2


Post Reply New Thread Subscribe

 
Thread Tools
TamPepper

 
Member Since: Mar 11, 2012
Posts: 60
TamPepper is on a distinguished road
Mac Specs: MacBookPro early 2012running Mavericks,MacMini Core i7 running Mavericks: iPhone 4s, iPad 3rd Gen

TamPepper is offline
I am taking my first steps in python 2.7 and am using Mountain Lion on a MacBook Pro
I cannot see what I am doing wrong re cv2

After installing Xcode and command tools, then Macports, I then used the following in a terminal

sudo port selfupdate
sudo port install py27-numpy
sudo port install opencv +python27

All went through without errors.
However when I enter "import cv2" in python it returns "no module named cv2"

Any help most appreciated
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,352
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
The module isn't called "cv2" which would explain the import problem. As you can see here, opencv is broken up into a variety of different modules.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks
TamPepper

 
Member Since: Mar 11, 2012
Posts: 60
TamPepper is on a distinguished road
Mac Specs: MacBookPro early 2012running Mavericks,MacMini Core i7 running Mavericks: iPhone 4s, iPad 3rd Gen

TamPepper is offline
Thanks for that
I had assumed that it was just like linux where it is called by import cv2
I have spent hours looking in the wrong direction. ie paths and the like
Much appreciated
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,352
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
I'm not sure why the Linux build would be any different but the package maintainers for your distro of choice may have patched opencv. I'm not sure why they would since the opencv devs are explicit with their naming conventions. But, whatever. Glad you go it working!

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks
TamPepper

 
Member Since: Mar 11, 2012
Posts: 60
TamPepper is on a distinguished road
Mac Specs: MacBookPro early 2012running Mavericks,MacMini Core i7 running Mavericks: iPhone 4s, iPad 3rd Gen

TamPepper is offline
Unfortunately I am stuck again !!
Reading through the opencv2 reference manual I tried the following code but it still throws an error on line using namespace cv;
Can you advise ?

#!/usr/bin/python
#include "opencv2/core/core.hpp"
#include "cv.h"
#include "highgui.h"
using namespace cv;
int main(int, char**) {
VideoCapture cap(0); if(!cap.isOpened()) return -1;
Mat frame, edges; namedWindow("edges",1); for(;
{
cap >> frame;
cvtColor(frame, edges, CV_BGR2GRAY); GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5); Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
return 0; }
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,352
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
Hold on here, why are you mixing Python code and C? You initially tried to import opencv as a Python module and now you're trying to import opencv headers in a C application.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks
TamPepper

 
Member Since: Mar 11, 2012
Posts: 60
TamPepper is on a distinguished road
Mac Specs: MacBookPro early 2012running Mavericks,MacMini Core i7 running Mavericks: iPhone 4s, iPad 3rd Gen

TamPepper is offline
Sorry about that, I had assumed the reference manual was all about python
I had blindly copied and pasted !!

So I want to capture from the web cam
#!/usr/bin/python
from here what do I need

this is what I use in windows python
import cv2
import numpy as np
c = cv2.VideoCapture(0)

while(1):
_,f = c.read()
cv2.imshow('e2',f)
if cv2.waitKey(5)==27:
break
cv2.destroyAllWindows()

I am well aware I have much reading to do, but was hoping to use the webcam as something to build code round as I progress
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,352
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
Quote:
Originally Posted by TamPepper View Post
import cv2
Quote:
Originally Posted by vansmith View Post
The module isn't called "cv2" which would explain the import problem. As you can see here, opencv is broken up into a variety of different modules.
I think I found your problem.

Execute the following at the command line:
Code:
python -c "help('modules')"
I think I might be able to find the right one in that list.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks
TamPepper

 
Member Since: Mar 11, 2012
Posts: 60
TamPepper is on a distinguished road
Mac Specs: MacBookPro early 2012running Mavericks,MacMini Core i7 running Mavericks: iPhone 4s, iPad 3rd Gen

TamPepper is offline
I think the answer is to stick to linux !!!
QUOTE Thanks

Post Reply New Thread Subscribe


« Darwin Streaming Server | Applescript Curl and Variable Help »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

All times are GMT -4. The time now is 12:28 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?