I use python and opencv to build a stereo tracker using two cameras.
The question is how to set up power line frequency filtration in openCV version 3.0.0 (or any orher). I know that the camera I use (microsoftHD3000) has this property and it can be set from v4l2 in linux and on windows I can use skype to set it once, but this is ugly.
Unfortunately I can not find the corresponding property in CAP_PROP_* constants.
What is the proper way to do it if any?
You can change the power line frequency setting as well as anything else using this answer, assuming you have installed GStreamer support (flag: -D WITH_GSTREAMER=ON).
If you don't have GStreamer, you can use v4l utils directly from terminal.
Since it is a prerequisite for installing OpenCV, so you should already have it.
Run:
for 50Hz:
v4l2-ctl --set-ctrl power_line_frequency=1
for 60Hz:
v4l2-ctl --set-ctrl power_line_frequency=2
to check current setting:
v4l2-ctl --all
Reference: Webcam flicker due to electricity grid frequency rate - Fedora Forums
Related
I am trying to detect Aruco markers through my camera using OpenCV for Python 2.7 on Debian 9.5, but I can't run my code because of an errore dealing with cv2.aruco.detectMarkers(). Running it on Windows, it does not have any problem. In particular, I wrote in my code:
cv2.aruco.detectMarkers(image=gray, dictionary=aruco_dict, parameters=parameters,
cameraMatrix=camera_matrix, distCoeff=camera_distortion)
where camera_matrix and camera_distortion are respectively the camera matrix and the camera distortion parameters I got by camera calibration.
More precisely, the error says that there's no cameraMatrix input parameter for the function cv2.aruco.detectMarkers. How do I fix this problem? Thank you very much in advance.
Maybe your error is due to your opencv version. Check it with:
cv2.__version__
Older versions of opencv (such as 3.2.0, that is maybe your default version for Debian 9) do not have cameraMatrix or distCoeff as input parameters of cv2.aruco.detectMarkers function.
If you are interested in getting newer versions of opencv for your OS (such as 4.1.0.25), you have to do:
sudo pip install opencv-contrib-python==4.1.0.25
If you are not, just remove cameraMatrix and distCoeff from your inputs, it would run anyway.
I was playing around with the Scapy sniff function and I wanted to add a filter into the parameters. So I added this filter:
pkt = sniff(count=1, filter='arp')
and the output i recieve is:
WARNING: Cannot set filter: libpcap is not available. Cannot compile filter !
I still get a packet that was sniffed, but for some reason the filter is not working.
I am running Mac OS Big Sur. I have libpcap installed using Homebrew and I have tcpdump installed using Homebrew.
I also saw online that you could manually initialize pcap on Scapy using
conf.use_pcap = True
However when I type this in I get:
WARNING: No libpcap provider available ! pcap won't be used
I'm sure it is just a small fix but I can't seem to figure out what I am doing wrong. If anyone can help that would be amazing!
Older versions of Python 3 assume that, on macOS, all shared libraries are in files located in one of a number of directories.
That is not the case in Big Sur; instead, a cache file is generated for system shared libraries, and at least some of the libraries from which the cache file is generated are not shipped with the OS.
This is one of the issues in CPython issue 41100, "Support macOS 11 and Apple Silicon Macs"; the fix is to look in the shared library cache as well as in the file system.
That issue says
Thank you to everyone who contributed to this major undertaking! A particular thank you to Lawrence for doing much of the initial work and paving the way. Now that 3.8 also supports Big Sur and Apple Silicon Macs as of the imminent 3.8.10 release, it's time to close this issue. If new concerns arise, pleasa open or use other issues.
So a sufficiently recent version of Python should fix this issue.
tldr:
$ brew install libpcap
$ ln -s /usr/local/opt/libpcap/lib/libpcap.a /usr/local/lib/libpcap.a
$ ln -s /usr/local/opt/libpcap/lib/libpcap.dylib /usr/local/lib/libpcap.dylib
Explanation (applicable for Python 3.9.1, Scapy 2.4.5 # Big Sur and libpcap installed by brew):
When you debug the Scapy sniff function, after a while you get to scapy.libs.winpcapy, line 36:
_lib_name = find_library("pcap")
find_library is located in ctypes.util, for POSIX it starts on line 72. On line 73 you can see that the library is expected as one of these filenames ['libpcap.dylib', 'pcap.dylib', 'pcap.framework/pcap'], being fed to dyld_find.
dyld_find is located in ctypes.macholib.dyld on line 121. If you iter through the chain on line 125 yourself, you find out that dyld_find is trying to succeed with one of these paths:
/usr/local/lib/
/Users/<user>/lib/
/usr/local/lib/
/lib/
/usr/lib/
In my case none of them contained the libpcap lib, which is installed in different location by brew.
The library sits in /usr/local/opt/libpcap/lib/.
And here you go, you just need to get the file libpcap.dylib (nothing wrong with libpcap.a too) into one of those paths searched by dyld_find. The two soft links above are one of a few more possible solutions.
I saw that psychopy now has support for RTL language:
http://www.psychopy.org/api/visual/textstim.html
https://discourse.psychopy.org/t/reshaping-english-text-to-arabic/4235/16
I used this manual to install the latest version using conda:
http://psychopy.org/installation.html
My version is: 1.90.2 with Python 3.5
However, when init TextStim with languageStyle I get an error:
from psychopy import visual
text_stim = visual.TextStim(self.window, height = height, wrapWidth = wrapWidth, bold= True, text= sentence, pos = (0,0) , color='white', languageStyle='RTL')
Any idea how can I use it?
Yes, #deceze is correct, this feature in the latest beta, available for download from this page: https://github.com/psychopy/psychopy/releases rather than the latest stable release available from http://psychopy.org/installation.html
EDIT: actually I see that you're installing PsychoPy via pip under Anaconda. I guess the pip version is also lagging behind the current beta release. You might need to clone or download from the PsychoPy GitHUb repository if you want the latest developer release running under your own Python installation.
Note that this feature still doesn't handle multi-line text correctly in Python experiments (the text flows from right to left but also from bottom-to-top). This is due to a limitation in the underlying pyglet library we use for drawing text. However, the latest betas also allow for generating online Javascript experiments that can be run from a browser. These handle Arabic text correctly without any issues whatsoever (and with no need to specify the language style setting at all).
I installed OpenCV3.2 + python3.6.1 from this installation guide. (For the paths needed in guide I typed:
Edit: I'm not sure, but I guess that I should install opencv under 3.6, not 3.6.1, please don't use my paths for your installation!
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin/libpython3.6.dylib
and
ls -d /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/include/python3.6m/)
My testing code is completely the same as the tutorial of OpenCV 3.2 documentation, but the output screen show nothing but a title:
import numpy as np
import cv2
img = cv2.imread('1.jpg',0)
cv2.imshow('image', img)
cv2.waitKey(0)
The result:
As the picture shown the content of the image is missing.
and it seems that it has something to do with my python, the icon is broken:
Please help me! I just want to use opencv for my school project...
If you just encounter the same problem, I can solve your problem. But you should take a look before you follow any further steps:
I will recommend you first delete OpenCV 3.2 from your mac.
Don't know how to delele? Here are the steps:
Read this answer first if you want to know what the following command do in details, then run the following command in your Terminal:
$> sudo find / -name "*opencv*" -exec rm -i {} \;
Please read every delete-checking message carefully, or you may delete some of your files containing "opencv" in filename, which may not related to OpenCV but may be your personal files.
Your cv2.so will still alive somewhere in your disk, go checkout where it is with the following command in Terminal:
$> ls -l /usr/local/lib/python3.6/site-packages/
In my case I found the cv2.so at .../python3.6/..., you should press 'tab' at /usr/local/lib/python then check out the site-packages folder for each python version (,which maybe you're about to re-install the OpenCV,) to search cv2.so. if you found it, delete it.
Install OpenCV3.2 with Homebrew for Python2.7 / 3.6. Just follow all the steps, and keep in mind that Homebrew is your best friend.
Edit: The link works for both Python2.7 and 3.6.
I ran into a similar issue but on the C++ API perspective. Credits go out to mattmyne.
Window autosize was not working for macOS using cocoa. The window's image dimensions could not be found. This has been fixed by removing IP64 specific synthesize in window_cocoa.mm that was causing null reference for the window's contentView image property in cvShowImage (image reference was not linked to _image).
In a nutshell, OpenCV tried to support both 32 and 64-bit ObjC compilers but since Apple no longer supports 32-bit, some image synthesizing operations resulted in null references in 64-bit machines. More info
To resolve this, locate the file window_cocoa.mm; if built from source it'll be in opencv/modules/highgui/src.
Change this
#implementation CVView
#if defined(__LP64__)
#synthesize image;
#else // 32-bit Obj-C does not have automatic synthesize
#synthesize image = _image;
#endif
To this
#implementation CVView
#synthesize image = _image;
Do the same thing for the CVWindow and CVSlider implementations to accommodate videos as well.
Recompile OpenCV and test out your code.
I am very new to raspberry pi and python.
I am trying write a progam using python on raspberry pi to use the Kinect. I aim to install OpenKinect on Raspberry pi.
So far I have done:
apt-cache search OpenKinect
sudo apt-get install python-freenect
sudo apt-get update
Next i tried writing a code in python from this link https://github.com/OpenKinect/libfreenect/blob/master/wrappers/python/demo_cv_async.py
When i try to run the programe, it says that
error in line 5,
import cv.
ImportError:no module named cv.
I am not sure if i have installed all the necessary files. I am also not sure what i have done wrong.
I also have been trying to look for tutorials on installing and using OpenKinect.
Congradtulations on starting python! That sounds like a complicated project to start on. You should probably try doing the tutorial first at python.org. I particularily like the google video tutorials (if you are a classroom kind of person): http://www.youtube.com/watch?v=tKTZoB2Vjuk
After that you can dig into more detailed stuff :)
It looks like you still dont have opencv package for python. Try to install it:
sudo apt-get install python-opencv
The OpenGL or GTK-Warning: Cannot open display. Or the other one you stated
Number of deviced found:1 GL thread write reg 0x0105 <= 0x00 freeglut(freenect-glview):
OpenGL GLX extension not supported by display ':o.o'
is because freenect does not support OpenGL. It probably uses EGL.
bmwesting (Brandt) wrote:
"The freenect library provides a demo for the Kinect called glview. The glview program will > not work with the Pi because the program is written using OpenGL. The Raspberry Pi only supports GLES through EGL.
It seems like you will be able to use libfreenect to grab the depth stream and rgb stream, > but will be unable to run the demo program because it uses the incorrect graphics API."
If you read through that thread, it should show the alternatives (i.e. ASUS XTion instead of Kinect). They reach 30fps at high (~ 1024x800) resolution for depth data if using console output mode. I plan to go for Xtion now too - and I hope to get deactivate as much as possible from the USB bus (as this seems to be the bottleneck, for the Kinect too I think).
When you install OpenCV using apt-get install python-opencv you are installing version 2. However, you can still use the methods from version 1 by doing so:
import cv2.cv as cv