× Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [2 lines of output] running egg_info error: PyObjC requires macOS to build [end of output]
That sounds frustrating! If you’re on pc and running into that issue, it sounds like it doesn’t like playsound. So try accessing your local environments dependencies to run the sound instead:) here’s a simple way of playing an mp3 file like we did: import os def play_sound(filename): os.system(f'start {filename}') play_sound('sound.mp3') # Replace 'sound.mp3' with your sound file
The `cv.detect_common_objects()` function from `cvlib` is designed to work on both Windows and macOS. The error you're encountering might be due to a different issue, such as an incorrect installation or an issue with the camera feed. To troubleshoot the error, you can try the following: 1. **Check Installation:** Ensure that `cvlib` is installed correctly in your Python environment. You can reinstall it using pip: ``` pip install cvlib ``` 2. **Check Camera Feed:** Make sure that your camera is connected properly and that it's providing frames to the script. You can print out the `frame` variable before calling `cv.detect_common_objects()` to check if it's `None`. 3. **Update Code:** Try updating your code to handle potential errors more gracefully. For example, you can add error handling around the `cv.detect_common_objects()` call to catch any exceptions: ```python try: bbox, label, conf = cv.detect_common_objects(frame) except Exception as e: print("Error detecting objects:", e) continue # Skip to the next iteration of the loop ``` This will print out any errors that occur during object detection and continue to the next iteration of the loop without crashing the script.
You're right, PyObjC is specifically for macOS and is not necessary for Windows or Linux systems since it's used to interact with macOS native libraries and frameworks. If you're on Windows or Linux, you won't need PyObjC for your Python projects on those platforms. SO! You do not have to import it in your code, nor install it:)
i'm getting the following error when trying to run this: OpenCV(4.9.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\darknet\darknet_io.cpp:705: error: (-215:Assertion failed) separator_index < line.size() in function 'cv::dnn::darknet::ReadDarknetFromCfgStream' error is occuring on the cv.detect_common_objects(frame) line
Hello sorry about your error, however, it doesn’t look like it’s the entire error message? Usually the cause of the error tells you what’s wrong at the bottom of the error, at least it does in Python.
Thank you sir If i want to add feature like giving response to a question " hey do you find an apple " by this model the response should be "yes apple found on the table or person hand". How to achieve this result sir
I am getting this error cv2.error: OpenCV(4.9.0) /io/opencv/modules/dnn/src/darknet/darknet_io.cpp:705: error: (-215:Assertion failed) separator_index < line.size() in function 'ReadDarknetFromCfgStream' please help
none type object has no attribute shape error is coming, i added a if frame is none and i see an error reading the frame how to fix it if there is an issue with camera connection please help
1. Image Loading Issue: Ensure that the image is loaded correctly using OpenCV (cv2.imread()). Check the path to the image file and make sure it exists. Verify that the image is loaded and not None. 2. Object Detection Result: If the object detection function doesn’t find any objects in the image, it might return None. Ensure that the object detection method is properly applied to the loaded image and that it’s capable of detecting objects in the given context. Here’s an example of how to handle these cases in your code: import cv2 import cvlib as cv image = cv2.imread('test1.jpg') if image is not None: result = cv.detect_common_objects(image) if result is not None and 'objects' in result: for obj in result['objects']: print(obj) else: print("No objects detected in the image.") else: print("Error loading the image.") This code checks if the image is loaded correctly and then proceeds with object detection. If the image loading fails or if no objects are detected, it provides an appropriate message.
If you're encountering an error stating "no module named tensorflow" even though you're not directly using TensorFlow in your code, it might be due to `cvlib` or other libraries indirectly requiring TensorFlow as a dependency. When you install `cvlib`, it installs `tensorflow` as one of its dependencies. So, even if you're not explicitly importing TensorFlow in your code, `cvlib` utilizes it internally for certain operations. To resolve this error, you'll need to ensure that `tensorflow` is installed in your Python environment. You can install it using pip: ``` pip install tensorflow Or if in pip3 then use: pip3 install tensorflow ``` Make sure to install TensorFlow in the same Python environment where you're running your script. After installing TensorFlow, the error should be resolved, and you should be able to run your code without encountering the "no module named tensorflow" error.
@@SalteeKiller cv2.error: OpenCV(4.9.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\darknet\darknet_io.cpp:705: error: (-215:Assertion failed) separator_index < line.size() in function 'cv::dnn::darknet::ReadDarknetFromCfgStream' can you define this eror it comes while running the code
The `cv.detect_common_objects()` command is usually associated with the `opencv-python` library's function for object detection. Could you please provide more details about the error message you're encountering? Knowing the specific error message will help in diagnosing and resolving the issue.
Hi sir, I couldn't install the 4th pip for PyObjc. The error message was "requirements to build wheel did not run successfully". What does this mean can you please help me to resolve it
Certainly! The error message "requirements to build wheel did not run successfully" typically means that some dependencies required to build the package aren't properly installed or configured. To resolve this for PyObjc, you might need to ensure you have Xcode (for macOS) or Visual Studio (for Windows) installed with their command-line tools to compile the package. Additionally, verifying that you have the necessary Python development headers and libraries installed could also help. For Windows, to resolve the "requirements to build wheel did not run successfully" issue while installing PyObjc via pip, you can follow these steps: 1. **Install Microsoft Visual C++ Build Tools:** - Download and install the Microsoft Visual C++ Build Tools from the official Microsoft website. 2. **Install PyObjc:** - After installing the build tools, try reinstalling PyObjc using pip by running the following command in your command prompt: ``` pip install pyobjc ``` 3. **Check Python and Pip Versions:** - Ensure you have the latest version of Python installed. You can check the version by running: ``` python --version ``` Also, verify your pip version using: ``` pip --version ``` 4. **Upgrade Pip and Setuptools:** - Update pip and setuptools to their latest versions by running: ``` pip install --upgrade pip setuptools ``` If the issue persists, it might be related to specific configurations or other dependencies on your system. Feel free to share any specific error messages or additional details you encounter while trying these steps. On a Mac, resolving the “requirements to build wheel did not run successfully” issue for PyObjc could involve a few steps: 1. Install Xcode Command Line Tools: • Open Terminal and run: xcode-select --install 1. • This command will prompt you to install the Xcode Command Line Tools. Follow the installation steps. 2. Update Homebrew (optional but recommended): • If you use Homebrew, you can update it to ensure you have the latest packages by running: brew update 3. Install PyObjc: • After ensuring Xcode Command Line Tools are installed, try installing PyObjc using pip in Terminal: pip install pyobjc 4. Verify Python and Pip: • Check your Python version in Terminal: python --version 4. • Also, verify your pip version: pip --version 5. Upgrade Pip and Setuptools: • You can update pip and setuptools to their latest versions by running: pip install --upgrade pip setuptools
Sure thing! The error `AttributeError: 'NoneType' object has no attribute 'shape'` is likely occurring because the `frame` variable is `None` at some point in your code. This might happen when the video feed is not being read correctly or when the object detection function (`cv.detect_common_objects`) fails to detect any objects. Here are some steps to handle this issue: 1. **Check Video Capture:** Make sure the video feed is being read correctly from your camera (`VideoCapture(1)`). You can add a check to ensure that the `frame` is not `None` before proceeding with object detection. 2. **Handle NoneType:** Update your code to handle the case where `frame` might be `None`. This can happen if the camera is not providing frames properly or if there's an issue with the connection. Here's an updated version of the code with error handling for `NoneType`: ```python import cv2 import cvlib as cv from cvlib.object_detection import draw_bbox from gtts import gTTS from playsound import playsound from food_facts import food_facts def speech(text): print(text) language = "en" output = gTTS(text=text, lang=language, slow=False) output.save("./sounds/output.mp3") playsound("./sounds/output.mp3") video = cv2.VideoCapture(1) labels = [] while True: ret, frame = video.read() if frame is not None: # Bounding box. # the cvlib library has learned some basic objects using object learning # usually it takes around 800 images for it to learn what a phone is. bbox, label, conf = cv.detect_common_objects(frame) output_image = draw_bbox(frame, bbox, label, conf) cv2.imshow("Detection", output_image) for item in label: if item in labels: pass else: labels.append(item) if cv2.waitKey(1) & 0xFF == ord("q"): break # If no objects are detected, handle the case gracefully if len(labels) == 0: print("No objects detected.") else: i = 0 new_sentence = [] for label in labels: if i == 0: new_sentence.append(f"I found a {label}, and, ") else: new_sentence.append(f"a {label},") i += 1 speech(" ".join(new_sentence)) speech("Here are the food facts I found for these items:") for label in labels: try: print(f" \t{label.title()}") food_facts(label) except: print("No food facts for this item") # Release the video capture and close any open windows video.release() cv2.destroyAllWindows() ``` This code will ensure that if `frame` is `None`, it will skip the object detection step and print "No objects detected." This should help prevent the `NoneType` error from occurring.
Yes so it usually means it can’t see where you have installed gtts as well as play sound. So double check those. Make sure you do all the correct spellings, including upper casing and such as I did in the video:) I don’t think gtts nor play sound has made any huge updates to cause this to not work anymore as it’s still working for others and myself at this point. So go back and double check WHERE, HOW and with which case sensitivity is needed to install it. Let us know!
i have one question. whenever i detect something on the camera and try to execute a function as a result of the camera detecting the object the camera lags a lot on python which makes everything very inconsistent, how do i fix that issue?
The lag you're experiencing might be due to the processing load when performing object detection in real-time. This happens because object detection is computationally intensive, especially when running it continuously on a live video feed. Here are some strategies to potentially reduce the lag: 1. **Optimize Object Detection:** Experiment with different object detection models or libraries. Some models are lighter and faster but might sacrifice accuracy. For example, YOLOv3 might be faster than YOLOv4 but slightly less accurate. 2. **Frame Skipping:** Process every nth frame instead of every frame. For instance, you might detect objects every 3 or 5 frames instead of every frame to reduce processing load. 3. **Reduce Image Size:** Decrease the resolution of frames if possible. Smaller images require less processing power for object detection. 4. **Hardware Acceleration:** Utilize GPU (if available) for acceleration. Many object detection libraries have GPU support for faster computation. Ensure your code is configured to use the GPU if it's available. 5. **Multithreading/Asynchronous Processing:** Use multithreading or asynchronous processing to separate the camera feed acquisition and object detection. This way, while detection occurs, the camera can continue capturing frames without waiting for the detection process to complete for each frame. 6. **Hardware Upgrade:** If possible, consider upgrading your hardware to a more powerful CPU or utilizing a dedicated machine for this task. Implementing these strategies could help mitigate the lag and improve the consistency of your real-time object detection application. Experimenting with these optimizations should allow you to find the right balance between speed and accuracy for your specific use case.
I am getting the following error even after successfully installing and importing required libraries :- cv2.error: OpenCV(4.9.0) /io/opencv/modules/dnn/src/darknet/darknet_io.cpp:705: error: (-215:Assertion failed) separator_index < line.size() in function 'ReadDarknetFromCfgStream' . I guess this is related to "dnn"" in OpenCV. How can I resolve this issue ? (OS is Windows 10)
It seems like the error `AttributeError: 'NoneType' object has no attribute 'shape'` is occurring due to the variable `frame` being `None` at some point in your code. This could happen if there's an issue reading frames from the video source (`video.read()` returning `None`). Ensure that your video source (`VideoCapture`) is functioning correctly and providing frames as expected. You might want to check the camera connection and whether it's capturing frames properly. You can add some error handling in the loop where you read frames to better understand the issue. For instance: ```python while True: ret, frame = video.read() if frame is None: print("Error reading the frame.") break # Rest of your code to process the frame... ``` This addition can help you identify if there's an issue with reading frames from the video source. If the frame is `None`, it means there's an issue with the camera connection or the video source not providing frames correctly.
It seems like the error `AttributeError: 'NoneType' object has no attribute 'shape'` is occurring due to the variable `frame` being `None` at some point in your code. This could happen if there's an issue reading frames from the video source (`video.read()` returning `None`). Ensure that your video source (`VideoCapture`) is functioning correctly and providing frames as expected. You might want to check the camera connection and whether it's capturing frames properly. You can add some error handling in the loop where you read frames to better understand the issue. For instance: ```python while True: ret, frame = video.read() if frame is None: print("Error reading the frame.") break # Rest of your code to process the frame... ``` This addition can help you identify if there's an issue with reading frames from the video source. If the frame is `None`, it means there's an issue with the camera connection or the video source not providing frames correctly.
If the comment section is still alive....I have a question....how come it is detecting objects on its own..... without having excess to any dataset of certain objects....or are you using a pre-trained model?
So OpenCV provides pre-trained models for certain algorithms like Haar Cascades, but for deep learning-based methods, you’d typically need to use models trained externally, such as the COCO dataset, and then integrate them into OpenCV for object detection tasks. These models can be used through OpenCV’s dnn module, allowing you to load pre-trained models and perform simple object detection on images or videos like person or phone or orange, car and so forth.
Hi, I know this is an old video but is there a way I can use this code in a website? (user opens website, clicks start streaming and it uses the default camera on phone/pc/laptop and this object detection to detect objects and show the names of the objects) I have no idea how to do it but I need to create one in order to graduate university :(
Yes this is just a backend, but you can use Flask and Jinja to use something called render_templates, which will allow you to use HTML with your Python code.
It seems there's a small syntax issue in your code. Here's a corrected version: ```python import cv2 import cvlib as cv image = cv2.imread('D:\pythonProject1\cars.jpeg') result = cv.detect_common_objects(image) if result and 'objects' in result: for obj in result['objects']: print(obj) else: print("No objects detected or an issue with the image.") ``` Make sure the path to your image file is correct and the file exists at that location. The indentation in Python is crucial, so ensure it's maintained correctly as shown in the corrected code. If the issue persists, double-check the installation of `cvlib` and the compatibility of versions to ensure there are no conflicts.
The error message "No module named 'tensorflow'" indicates that TensorFlow, a required dependency for the object detection module in OpenCV, is not installed on your system. To resolve this issue, you'll need to install TensorFlow alongside OpenCV. You can do this by running: ```bash pip install opencv-python tensorflow ``` This command will install both OpenCV and TensorFlow. After the installation is complete, you should be able to use the `cv.detect_common_objects()` function without encountering the "No module named 'tensorflow'" error.
@@SalteeKiller I keep getting this same module-error about tensorflow, but 3 questions about this: 1- If you do "pip install" for opencv-contrib-python and tensorflow, do they have to be done at one line, or is seperately one after the other okay too? I did not get any errors while installing, so I guess okay. 2- After having successfully installed both dependancies, I keep getting the same error. Should I not also do "import tensorflow" in my source code? I don't see you doing that. 3- If I see correctly you are using Pycharm as SDK, me too, but if you click on 'terminal' at the bottom of the screen, does this automaticly imply that you are in the right VirtualENViroment? Sorry to bother you with all these questions, let me know if I need to stop.
@@Ernie-Tech 1. Installation of packages using pip: You can install packages using pip separately or in a single line. Both methods work fine. For example: • pip install opencv-contrib-python • pip install tensorflow Running these commands separately should install the packages without issues. 2. Importing TensorFlow: Yes, after installing TensorFlow, you’ll need to import it into your Python source code using import tensorflow. If you’re utilizing TensorFlow functionalities in your code, it’s essential to import the library to access its functions and modules. Not seeing the import statement might be an oversight in the code you’re referring to. 3. PyCharm Terminal and Virtual Environment: When you open the terminal in PyCharm, it depends on the configuration of your project and PyCharm settings. If you’ve set up a virtual environment for your project, opening the terminal within PyCharm should automatically activate that virtual environment. However, it’s good practice to verify the active environment by checking if the terminal prompt shows the environment name. You can confirm the active virtual environment in the terminal by observing the environment name in the terminal prompt or using a command like conda info --envs (if using Conda) or pip list to see the installed packages, ensuring they belong to the intended environment.
Using CUDA with a project involves leveraging NVIDIA’s CUDA parallel computing platform and programming model to harness the power of NVIDIA GPUs for computations. To use CUDA effectively: 1. Install CUDA Toolkit: Ensure you have the CUDA Toolkit installed on your system. The version you install should be compatible with your GPU and system configuration. 2. CUDA-Accelerated Libraries: Many libraries offer CUDA support for faster computation on GPUs. Libraries like TensorFlow, PyTorch, and cuDNN (CUDA Deep Neural Network library) provide CUDA-accelerated functions for machine learning tasks. 3. Programming in CUDA: If your project requires specific operations that aren’t covered by existing libraries, you might need to write CUDA kernels in CUDA C/C++ to execute on the GPU. These kernels can be integrated into your Python code using tools like PyCUDA or Numba. 4. GPU Availability: Ensure that your environment has access to a GPU with CUDA support. In platforms like Google Colab, you can access GPU-enabled instances, allowing you to run CUDA-based computations. Here’s a high-level overview of how you might use CUDA with a Python project: • TensorFlow/PyTorch: Enable GPU support when initializing your deep learning models. For TensorFlow, this involves using tf.config.experimental.list_physical_devices('GPU') and setting tf.device('/GPU:0') for operations. • CuPy: For array operations similar to NumPy but optimized for GPUs, you can use CuPy, a NumPy-like library accelerated by CUDA. • PyCUDA/Numba: If you need to write custom CUDA kernels, PyCUDA allows you to write CUDA code directly in Python, while Numba provides a just-in-time compiler that can convert Python functions to CUDA kernels. To use CUDA effectively, understanding parallel computing principles and CUDA programming is essential. Additionally, ensure compatibility between CUDA versions, GPU drivers, and libraries to avoid compatibility issues.
It is showing "nomodulefound" error and it's saying "No module named tensorflow" Its saying the error is in importing drawbbox from cvlib.object_detection
For Windows, while installing PyObjc via pip, you can follow these steps: 1. **Install Microsoft Visual C++ Build Tools:** - Download and install the Microsoft Visual C++ Build Tools from the official Microsoft website. 2. **Install PyObjc:** - After installing the build tools, try reinstalling PyObjc using pip by running the following command in your command prompt: ``` pip install pyobjc ``` 3. **Check Python and Pip Versions:** - Ensure you have the latest version of Python installed. You can check the version by running: ``` python --version ``` Also, verify your pip version using: ``` pip --version ``` 4. **Upgrade Pip and Setuptools:** - Update pip and setuptools to their latest versions by running: ``` pip install --upgrade pip setuptools ```
very very very impressive the way you so easily program this, my compliments! I'm wondering if I could count the fish in my pond with a life camera stream, using your code only to tell the difference between all the different fish (>100) and keep track of them swimming by. Do you think using your example I would make a good start in this?
Counting individual fish in a live camera stream can be quite challenging, especially distinguishing between a large number of fish with varying shapes, colors, and movements. While object detection can help identify and localize objects (in this case, fish), counting them accurately might require more specialized techniques. Here’s an approach you might consider: 1. Object Detection: Use the object detection techniques you’ve been working with to identify fish in the video stream. This would involve the use of YOLO, SSD, or similar models to detect and label fish. 2. Tracking: Implement a tracking algorithm to keep track of individual fish as they move across frames. Various tracking algorithms, like centroid tracking or Kalman filtering, can help maintain identities of different objects (fish) across frames. 3. Counting: Develop a counting mechanism that keeps track of unique identities assigned to each fish. As new fish are detected, assign them unique IDs and update their positions through the tracking mechanism. Then, count the unique IDs to determine the total number of distinct fish detected. This process requires combining object detection with object tracking and maintaining a system to differentiate between individual fish. It might involve some trial and error to fine-tune the detection and tracking algorithms for accurate counting, especially in complex environments like a pond with multiple fish. Additionally, the success of this approach might depend on factors such as lighting conditions, water clarity, fish size, and the camera’s positioning. Calibration and adjustments may be needed to account for these variables.
@@SalteeKiller Thank you so very much for putting me on the right path. I'm quite a newbe to python and pycharm, but I will give it my best shot. At least I'm very inspired by your works and reply!!!
Thank you for such a simple introduction to detecting objects with OpenCV. It seems like google colab doesn't allow installation of PyObjC. I used "pip3 install PyObj," and every time I landed on the same error, first it said "Warning Discarding" it discards the pyobj wheel and then tries installing multiple versions but leads to the same error. Do you know if colab can be used for this project?
Google Colab provides a Python environment that allows installing many packages, but it does have some limitations, especially when it comes to certain system-level packages or those requiring direct access to hardware features. `PyObjC` is a Python-Objective-C bridge, primarily used on macOS. It's unlikely that `PyObjC` would be compatible or even necessary within Google Colab, which runs on Linux environments. If your project relies heavily on `PyObjC`, it might face challenges running on Colab due to the different operating systems and hardware configurations. Consider exploring alternatives that don't rely on specific macOS functionalities or libraries. If your project requires Mac-specific features, you might need to work on a local macOS environment or a platform that supports macOS-specific libraries. Alternatively, you could explore cloud solutions that provide macOS environments, but these might come with additional costs.
Thank you for the video and I understand them pretty easily :D but are you using visual studio 2022? I tried to run on it but its always throwing me errors that there's no module named cvlib even though i have installed and uninstalled it multiple times... as for spyder, i can run on it once with the playsound feature then it will throw an error saying Permission denied to access my folder. For videocapture indexing, I tried put '1' but its only showing my statics in my camera so i had to use '0'
It seems like you're encountering multiple issues. Let's tackle them step by step. For the 'no module named cvlib' error, ensure that you've installed the module in the correct Python environment. Sometimes, installations might not sync with the active environment. Regarding Spyder and the permission denied issue, it could be related to the access permissions of the folder you're working in. Try running Spyder as an administrator or ensuring that the folder has the necessary permissions for read and write operations. When dealing with VideoCapture indexing, '0' usually represents the default camera, while '1' might refer to an external camera. The 'O' might stand for the camera in a specific OpenCV notation.
So the four loops that we did in the video is for using multiple images inside the video. So you have to do is take out the four loop, then by doing so it will just be doing one image. Then when you select a video source index zero or one or whatever, instead of doing, the indexing, just put in the path of your image
Here's a simple example of how you might load an image with OpenCV and perform object detection: ```python import cv2 as cv # Load the image image = cv.imread('path_to_your_image.jpg') # Perform object detection result = cv.detect_common_objects(image) # Check the result if result and 'objects' in result: for obj in result['objects']: print(obj) else: print("No objects detected or an issue with the image.") ``` Make sure to replace `'path_to_your_image.jpg'` with the actual path to your image file. This code snippet will load the image, perform object detection using `cv.detect_common_objects()`, and print the detected objects. If the image loading process or the result is 'None', it might lead to the error you've encountered.
Oh no! The `detect_common_objects` method is a part of the `cvlib` library, not directly within OpenCV (`cv2`). When you mentioned the error with 'no module named cvlib', it seems that the `cvlib` library might not have been correctly installed or imported in your code. Ensure that you've installed `cvlib` via pip: `pip install cvlib`. Then, in your Python script, make sure to import it correctly: ```python import cv2 import cvlib as cv # Your code # Example usage of detect_common_objects method image = cv2.imread('your_image.jpg') bbox, label, conf = cv.detect_common_objects(image) ``` If the error persists even after installing and importing `cvlib` correctly, it might be worth checking the version compatibility of the installed libraries. Sometimes, conflicts between different library versions could cause such attribute errors.
@@SalteeKiller Thank you for the reply but when i installed and imported cvlib and used detect_common_objects from cvlib it still shows cvlib does not have an attribute called detect_commopn_objects. i will post my code below import cv2 import cvlib as cv image = cv2.imread('D:\pythonProject1\cars.jpeg') result = cv.detect_common_objects(image) if result and 'objects' in result: for obj in result['objects']: print(obj) else: print("No objects detected or an issue with the image.")
For anyone doing this today/in the future: You can add these 2 lines of code to the bottom of your program if you don’t want the video capture to linger. He didn’t do it in the video. video.release() Cv2.destroyAllWindows
The error message "Non-type has no attribute 'shape'" typically occurs when you're trying to access the 'shape' attribute of a variable that happens to be 'None' or a non-existent object. This could happen in the context of object detection if there's an issue with the input image or the output from the `cv.detect_common_objects()` function. It's important to ensure that the image you're passing for object detection is valid and properly loaded before using it with this function. Make sure you're loading the image correctly and check if the image loading process might be returning 'None' instead of the actual image data. You can also check if the image file path or object itself is properly initialized and accessible. Here's a simple example of how you might load an image with OpenCV and perform object detection: ```python import cv2 as cv # Load the image image = cv.imread('path_to_your_image.jpg') # Perform object detection result = cv.detect_common_objects(image) # Check the result if result and 'objects' in result: for obj in result['objects']: print(obj) else: print("No objects detected or an issue with the image.") ``` Make sure to replace `'path_to_your_image.jpg'` with the actual path to your image file. This code snippet will load the image, perform object detection using `cv.detect_common_objects()`, and print the detected objects. If the image loading process or the result is 'None', it might lead to the error you've encountered.
Here’s the git repo: github.com/107124/object-detection
Bro that 3 days later hit me right in the gut trying to get this to work on arch Linux is so difficult but we’re almost there lol
Love this you just saved my degree
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [2 lines of output]
running egg_info
error: PyObjC requires macOS to build
[end of output]
That sounds frustrating! If you’re on pc and running into that issue, it sounds like it doesn’t like playsound. So try accessing your local environments dependencies to run the sound instead:) here’s a simple way of playing an mp3 file like we did:
import os
def play_sound(filename):
os.system(f'start {filename}')
play_sound('sound.mp3')
# Replace 'sound.mp3' with your sound file
i am using windows and i get error in cv.detect_common_objects(frame), what i have learned it works on mac only so any alternative command for windows
The `cv.detect_common_objects()` function from `cvlib` is designed to work on both Windows and macOS. The error you're encountering might be due to a different issue, such as an incorrect installation or an issue with the camera feed.
To troubleshoot the error, you can try the following:
1. **Check Installation:** Ensure that `cvlib` is installed correctly in your Python environment. You can reinstall it using pip:
```
pip install cvlib
```
2. **Check Camera Feed:** Make sure that your camera is connected properly and that it's providing frames to the script. You can print out the `frame` variable before calling `cv.detect_common_objects()` to check if it's `None`.
3. **Update Code:** Try updating your code to handle potential errors more gracefully. For example, you can add error handling around the `cv.detect_common_objects()` call to catch any exceptions:
```python
try:
bbox, label, conf = cv.detect_common_objects(frame)
except Exception as e:
print("Error detecting objects:", e)
continue # Skip to the next iteration of the loop
```
This will print out any errors that occur during object detection and continue to the next iteration of the loop without crashing the script.
Error: installing PyObjC. It says PyObjC is for Apple/Mac. Not required for windows/linux systems.
You're right, PyObjC is specifically for macOS and is not necessary for Windows or Linux systems since it's used to interact with macOS native libraries and frameworks. If you're on Windows or Linux, you won't need PyObjC for your Python projects on those platforms.
SO! You do not have to import it in your code, nor install it:)
One of the best tutor. You are awesome bro...!
i'm getting the following error when trying to run this:
OpenCV(4.9.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\darknet\darknet_io.cpp:705: error: (-215:Assertion failed) separator_index < line.size() in function 'cv::dnn::darknet::ReadDarknetFromCfgStream'
error is occuring on the cv.detect_common_objects(frame) line
Hello sorry about your error, however, it doesn’t look like it’s the entire error message? Usually the cause of the error tells you what’s wrong at the bottom of the error, at least it does in Python.
Thank you sir
If i want to add feature like giving response to
a question " hey do you find an apple " by this model the response should be "yes apple found on the table or person hand". How to achieve this result sir
I am getting this error
cv2.error: OpenCV(4.9.0) /io/opencv/modules/dnn/src/darknet/darknet_io.cpp:705: error: (-215:Assertion failed) separator_index < line.size() in function 'ReadDarknetFromCfgStream'
please help
same here did you find a fix?
same here did you get a fix to this problem?
none type object has no attribute shape error is coming, i added a if frame is none and i see an error reading the frame how to fix it if there is an issue with camera connection please help
1. Image Loading Issue: Ensure that the image is loaded correctly using OpenCV (cv2.imread()). Check the path to the image file and make sure it exists. Verify that the image is loaded and not None.
2. Object Detection Result: If the object detection function doesn’t find any objects in the image, it might return None. Ensure that the object detection method is properly applied to the loaded image and that it’s capable of detecting objects in the given context.
Here’s an example of how to handle these cases in your code:
import cv2
import cvlib as cv
image = cv2.imread('test1.jpg')
if image is not None:
result = cv.detect_common_objects(image)
if result is not None and 'objects' in result:
for obj in result['objects']:
print(obj)
else:
print("No objects detected in the image.")
else:
print("Error loading the image.")
This code checks if the image is loaded correctly and then proceeds with object detection. If the image loading fails or if no objects are detected, it provides an appropriate message.
while runing this code an eror no module named tenserflow is found is coming there need of tenserflow library for this code then why is that eror
If you're encountering an error stating "no module named tensorflow" even though you're not directly using TensorFlow in your code, it might be due to `cvlib` or other libraries indirectly requiring TensorFlow as a dependency.
When you install `cvlib`, it installs `tensorflow` as one of its dependencies. So, even if you're not explicitly importing TensorFlow in your code, `cvlib` utilizes it internally for certain operations.
To resolve this error, you'll need to ensure that `tensorflow` is installed in your Python environment. You can install it using pip:
```
pip install tensorflow
Or if in pip3 then use:
pip3 install tensorflow
```
Make sure to install TensorFlow in the same Python environment where you're running your script. After installing TensorFlow, the error should be resolved, and you should be able to run your code without encountering the "no module named tensorflow" error.
@@SalteeKiller cv2.error: OpenCV(4.9.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\darknet\darknet_io.cpp:705: error: (-215:Assertion failed) separator_index < line.size() in function 'cv::dnn::darknet::ReadDarknetFromCfgStream'
can you define this eror it comes while running the code
Hii , I'm getting error in cv.detect_common_objects() command ,i have followed each and every step as you have done ,but still don't able to debug it
The `cv.detect_common_objects()` command is usually associated with the `opencv-python` library's function for object detection. Could you please provide more details about the error message you're encountering? Knowing the specific error message will help in diagnosing and resolving the issue.
@@SalteeKiller i have the same issue cannot fix it
Hi sir, I couldn't install the 4th pip for PyObjc. The error message was "requirements to build wheel did not run successfully". What does this mean can you please help me to resolve it
Certainly! The error message "requirements to build wheel did not run successfully" typically means that some dependencies required to build the package aren't properly installed or configured. To resolve this for PyObjc, you might need to ensure you have Xcode (for macOS) or Visual Studio (for Windows) installed with their command-line tools to compile the package. Additionally, verifying that you have the necessary Python development headers and libraries installed could also help.
For Windows, to resolve the "requirements to build wheel did not run successfully" issue while installing PyObjc via pip, you can follow these steps:
1. **Install Microsoft Visual C++ Build Tools:**
- Download and install the Microsoft Visual C++ Build Tools from the official Microsoft website.
2. **Install PyObjc:**
- After installing the build tools, try reinstalling PyObjc using pip by running the following command in your command prompt:
```
pip install pyobjc
```
3. **Check Python and Pip Versions:**
- Ensure you have the latest version of Python installed. You can check the version by running:
```
python --version
```
Also, verify your pip version using:
```
pip --version
```
4. **Upgrade Pip and Setuptools:**
- Update pip and setuptools to their latest versions by running:
```
pip install --upgrade pip setuptools
```
If the issue persists, it might be related to specific configurations or other dependencies on your system. Feel free to share any specific error messages or additional details you encounter while trying these steps.
On a Mac, resolving the “requirements to build wheel did not run successfully” issue for PyObjc could involve a few steps:
1. Install Xcode Command Line Tools:
• Open Terminal and run:
xcode-select --install
1.
• This command will prompt you to install the Xcode Command Line Tools. Follow the installation steps.
2. Update Homebrew (optional but recommended):
• If you use Homebrew, you can update it to ensure you have the latest packages by running:
brew update
3. Install PyObjc:
• After ensuring Xcode Command Line Tools are installed, try installing PyObjc using pip in Terminal:
pip install pyobjc
4. Verify Python and Pip:
• Check your Python version in Terminal:
python --version
4.
• Also, verify your pip version:
pip --version
5. Upgrade Pip and Setuptools:
• You can update pip and setuptools to their latest versions by running:
pip install --upgrade pip setuptools
Good day sir. I am using python 3.12.1 but your code when run is said cvlib not found, what should i do?
pip install cvlib
How do i open the window of the recognition???
AttributeError: 'NoneType' object has no attribute 'shape'
this error is occuring while running
Sure thing! The error `AttributeError: 'NoneType' object has no attribute 'shape'` is likely occurring because the `frame` variable is `None` at some point in your code. This might happen when the video feed is not being read correctly or when the object detection function (`cv.detect_common_objects`) fails to detect any objects.
Here are some steps to handle this issue:
1. **Check Video Capture:**
Make sure the video feed is being read correctly from your camera (`VideoCapture(1)`). You can add a check to ensure that the `frame` is not `None` before proceeding with object detection.
2. **Handle NoneType:**
Update your code to handle the case where `frame` might be `None`. This can happen if the camera is not providing frames properly or if there's an issue with the connection.
Here's an updated version of the code with error handling for `NoneType`:
```python
import cv2
import cvlib as cv
from cvlib.object_detection import draw_bbox
from gtts import gTTS
from playsound import playsound
from food_facts import food_facts
def speech(text):
print(text)
language = "en"
output = gTTS(text=text, lang=language, slow=False)
output.save("./sounds/output.mp3")
playsound("./sounds/output.mp3")
video = cv2.VideoCapture(1)
labels = []
while True:
ret, frame = video.read()
if frame is not None:
# Bounding box.
# the cvlib library has learned some basic objects using object learning
# usually it takes around 800 images for it to learn what a phone is.
bbox, label, conf = cv.detect_common_objects(frame)
output_image = draw_bbox(frame, bbox, label, conf)
cv2.imshow("Detection", output_image)
for item in label:
if item in labels:
pass
else:
labels.append(item)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
# If no objects are detected, handle the case gracefully
if len(labels) == 0:
print("No objects detected.")
else:
i = 0
new_sentence = []
for label in labels:
if i == 0:
new_sentence.append(f"I found a {label}, and, ")
else:
new_sentence.append(f"a {label},")
i += 1
speech(" ".join(new_sentence))
speech("Here are the food facts I found for these items:")
for label in labels:
try:
print(f"
\t{label.title()}")
food_facts(label)
except:
print("No food facts for this item")
# Release the video capture and close any open windows
video.release()
cv2.destroyAllWindows()
```
This code will ensure that if `frame` is `None`, it will skip the object detection step and print "No objects detected." This should help prevent the `NoneType` error from occurring.
Hey, it's giving me a warning "Unresolved reference 'gtts'" and the same thing for gTTS and playsound. Any fixes?
Yes so it usually means it can’t see where you have installed gtts as well as play sound. So double check those. Make sure you do all the correct spellings, including upper casing and such as I did in the video:) I don’t think gtts nor play sound has made any huge updates to cause this to not work anymore as it’s still working for others and myself at this point. So go back and double check WHERE, HOW and with which case sensitivity is needed to install it. Let us know!
@@SalteeKiller will this tutorial work on pycharm?
@@moreflozz yes I did this in PyCharm in the video
@@SalteeKiller okay, thanks!
Hello sir, can i also perform what you did using visual studio code?
i have one question. whenever i detect something on the camera and try to execute a function as a result of the camera detecting the object the camera lags a lot on python which makes everything very inconsistent, how do i fix that issue?
The lag you're experiencing might be due to the processing load when performing object detection in real-time. This happens because object detection is computationally intensive, especially when running it continuously on a live video feed.
Here are some strategies to potentially reduce the lag:
1. **Optimize Object Detection:** Experiment with different object detection models or libraries. Some models are lighter and faster but might sacrifice accuracy. For example, YOLOv3 might be faster than YOLOv4 but slightly less accurate.
2. **Frame Skipping:** Process every nth frame instead of every frame. For instance, you might detect objects every 3 or 5 frames instead of every frame to reduce processing load.
3. **Reduce Image Size:** Decrease the resolution of frames if possible. Smaller images require less processing power for object detection.
4. **Hardware Acceleration:** Utilize GPU (if available) for acceleration. Many object detection libraries have GPU support for faster computation. Ensure your code is configured to use the GPU if it's available.
5. **Multithreading/Asynchronous Processing:** Use multithreading or asynchronous processing to separate the camera feed acquisition and object detection. This way, while detection occurs, the camera can continue capturing frames without waiting for the detection process to complete for each frame.
6. **Hardware Upgrade:** If possible, consider upgrading your hardware to a more powerful CPU or utilizing a dedicated machine for this task.
Implementing these strategies could help mitigate the lag and improve the consistency of your real-time object detection application. Experimenting with these optimizations should allow you to find the right balance between speed and accuracy for your specific use case.
thank you for the advice
I'm getting error in pip install gtts playsound , please help me out with this
Please reply soon
do you know why it throws an error. requires tensorflow?
pyobjc is not for windows it only works with macos i have the same problem wondering if u found the soulution
I am getting the following error even after successfully installing and importing required libraries :-
cv2.error: OpenCV(4.9.0) /io/opencv/modules/dnn/src/darknet/darknet_io.cpp:705: error: (-215:Assertion failed) separator_index < line.size() in function 'ReadDarknetFromCfgStream' . I guess this is related to "dnn"" in OpenCV.
How can I resolve this issue ? (OS is Windows 10)
hey did u fix it?
'NoneType' object has no attribute 'shape'
Same
Same. @SalteeKiller
It seems like the error `AttributeError: 'NoneType' object has no attribute 'shape'` is occurring due to the variable `frame` being `None` at some point in your code. This could happen if there's an issue reading frames from the video source (`video.read()` returning `None`).
Ensure that your video source (`VideoCapture`) is functioning correctly and providing frames as expected. You might want to check the camera connection and whether it's capturing frames properly.
You can add some error handling in the loop where you read frames to better understand the issue. For instance:
```python
while True:
ret, frame = video.read()
if frame is None:
print("Error reading the frame.")
break
# Rest of your code to process the frame...
```
This addition can help you identify if there's an issue with reading frames from the video source. If the frame is `None`, it means there's an issue with the camera connection or the video source not providing frames correctly.
Cv2.VideoCapture(0)->try for 0
when I am running for the first time its getting an attribute error
How to fix it
Height, Width = image.shape[:2]
^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'shape'
how do i resolve this?
It seems like the error `AttributeError: 'NoneType' object has no attribute 'shape'` is occurring due to the variable `frame` being `None` at some point in your code. This could happen if there's an issue reading frames from the video source (`video.read()` returning `None`).
Ensure that your video source (`VideoCapture`) is functioning correctly and providing frames as expected. You might want to check the camera connection and whether it's capturing frames properly.
You can add some error handling in the loop where you read frames to better understand the issue. For instance:
```python
while True:
ret, frame = video.read()
if frame is None:
print("Error reading the frame.")
break
# Rest of your code to process the frame...
```
This addition can help you identify if there's an issue with reading frames from the video source. If the frame is `None`, it means there's an issue with the camera connection or the video source not providing frames correctly.
it says that in the first run to see the video box
If the comment section is still alive....I have a question....how come it is detecting objects on its own..... without having excess to any dataset of certain objects....or are you using a pre-trained model?
So OpenCV provides pre-trained models for certain algorithms like Haar Cascades, but for deep learning-based methods, you’d typically need to use models trained externally, such as the COCO dataset, and then integrate them into OpenCV for object detection tasks. These models can be used through OpenCV’s dnn module, allowing you to load pre-trained models and perform simple object detection on images or videos like person or phone or orange, car and so forth.
@@SalteeKiller thanks bud! This helped a lot
Hi, I know this is an old video but is there a way I can use this code in a website? (user opens website, clicks start streaming and it uses the default camera on phone/pc/laptop and this object detection to detect objects and show the names of the objects) I have no idea how to do it but I need to create one in order to graduate university :(
Yes this is just a backend, but you can use Flask and Jinja to use something called render_templates, which will allow you to use HTML with your Python code.
is yolo required in this ? You haven't mentioned that if it is required and it is showing me that file not found error yolo.
Yolo is not required for this project
@@SalteeKiller thank you thats a quick reply ever I had seen in RUclips
It seems there's a small syntax issue in your code. Here's a corrected version:
```python
import cv2
import cvlib as cv
image = cv2.imread('D:\pythonProject1\cars.jpeg')
result = cv.detect_common_objects(image)
if result and 'objects' in result:
for obj in result['objects']:
print(obj)
else:
print("No objects detected or an issue with the image.")
```
Make sure the path to your image file is correct and the file exists at that location. The indentation in Python is crucial, so ensure it's maintained correctly as shown in the corrected code. If the issue persists, double-check the installation of `cvlib` and the compatibility of versions to ensure there are no conflicts.
can we also detect drones using this ?
it said that "No module named 'tensorflow' so how do I?
run "pip install tensorflow" in your terminal
The error message "No module named 'tensorflow'" indicates that TensorFlow, a required dependency for the object detection module in OpenCV, is not installed on your system.
To resolve this issue, you'll need to install TensorFlow alongside OpenCV. You can do this by running:
```bash
pip install opencv-python tensorflow
```
This command will install both OpenCV and TensorFlow. After the installation is complete, you should be able to use the `cv.detect_common_objects()` function without encountering the "No module named 'tensorflow'" error.
@@SalteeKiller I keep getting this same module-error about tensorflow, but 3 questions about this:
1- If you do "pip install" for opencv-contrib-python and tensorflow, do they have to be done at one line, or is seperately one after the other okay too? I did not get any errors while installing, so I guess okay.
2- After having successfully installed both dependancies, I keep getting the same error. Should I not also do "import tensorflow" in my source code? I don't see you doing that.
3- If I see correctly you are using Pycharm as SDK, me too, but if you click on 'terminal' at the bottom of the screen, does this automaticly imply that you are in the right VirtualENViroment?
Sorry to bother you with all these questions, let me know if I need to stop.
@@Ernie-Tech
1. Installation of packages using pip:
You can install packages using pip separately or in a single line. Both methods work fine. For example:
• pip install opencv-contrib-python
• pip install tensorflow
Running these commands separately should install the packages without issues.
2. Importing TensorFlow:
Yes, after installing TensorFlow, you’ll need to import it into your Python source code using import tensorflow. If you’re utilizing TensorFlow functionalities in your code, it’s essential to import the library to access its functions and modules. Not seeing the import statement might be an oversight in the code you’re referring to.
3. PyCharm Terminal and Virtual Environment:
When you open the terminal in PyCharm, it depends on the configuration of your project and PyCharm settings. If you’ve set up a virtual environment for your project, opening the terminal within PyCharm should automatically activate that virtual environment. However, it’s good practice to verify the active environment by checking if the terminal prompt shows the environment name.
You can confirm the active virtual environment in the terminal by observing the environment name in the terminal prompt or using a command like conda info --envs (if using Conda) or pip list to see the installed packages, ensuring they belong to the intended environment.
how can i enable cuda for this project
Using CUDA with a project involves leveraging NVIDIA’s CUDA parallel computing platform and programming model to harness the power of NVIDIA GPUs for computations. To use CUDA effectively:
1. Install CUDA Toolkit: Ensure you have the CUDA Toolkit installed on your system. The version you install should be compatible with your GPU and system configuration.
2. CUDA-Accelerated Libraries: Many libraries offer CUDA support for faster computation on GPUs. Libraries like TensorFlow, PyTorch, and cuDNN (CUDA Deep Neural Network library) provide CUDA-accelerated functions for machine learning tasks.
3. Programming in CUDA: If your project requires specific operations that aren’t covered by existing libraries, you might need to write CUDA kernels in CUDA C/C++ to execute on the GPU. These kernels can be integrated into your Python code using tools like PyCUDA or Numba.
4. GPU Availability: Ensure that your environment has access to a GPU with CUDA support. In platforms like Google Colab, you can access GPU-enabled instances, allowing you to run CUDA-based computations.
Here’s a high-level overview of how you might use CUDA with a Python project:
• TensorFlow/PyTorch: Enable GPU support when initializing your deep learning models. For TensorFlow, this involves using tf.config.experimental.list_physical_devices('GPU') and setting tf.device('/GPU:0') for operations.
• CuPy: For array operations similar to NumPy but optimized for GPUs, you can use CuPy, a NumPy-like library accelerated by CUDA.
• PyCUDA/Numba: If you need to write custom CUDA kernels, PyCUDA allows you to write CUDA code directly in Python, while Numba provides a just-in-time compiler that can convert Python functions to CUDA kernels.
To use CUDA effectively, understanding parallel computing principles and CUDA programming is essential. Additionally, ensure compatibility between CUDA versions, GPU drivers, and libraries to avoid compatibility issues.
What IDE are you using?
This is PyCharm
It is showing "nomodulefound" error and it's saying "No module named tensorflow"
Its saying the error is in importing drawbbox from cvlib.object_detection
pip install tensorflow
What alternatives we can use on windows??
For Windows, while installing PyObjc via pip, you can follow these steps:
1. **Install Microsoft Visual C++ Build Tools:**
- Download and install the Microsoft Visual C++ Build Tools from the official Microsoft website.
2. **Install PyObjc:**
- After installing the build tools, try reinstalling PyObjc using pip by running the following command in your command prompt:
```
pip install pyobjc
```
3. **Check Python and Pip Versions:**
- Ensure you have the latest version of Python installed. You can check the version by running:
```
python --version
```
Also, verify your pip version using:
```
pip --version
```
4. **Upgrade Pip and Setuptools:**
- Update pip and setuptools to their latest versions by running:
```
pip install --upgrade pip setuptools
```
Thanks. If I need to detect, especially, object how to do this.
Not working on latest Mac OS on m3
I’m getting reports it’s working on M3. Double check installations and source code:
github.com/Kent-Taylor/object-detection/blob/main/main.py
very very very impressive the way you so easily program this, my compliments! I'm wondering if I could count the fish in my pond with a life camera stream, using your code only to tell the difference between all the different fish (>100) and keep track of them swimming by. Do you think using your example I would make a good start in this?
Counting individual fish in a live camera stream can be quite challenging, especially distinguishing between a large number of fish with varying shapes, colors, and movements. While object detection can help identify and localize objects (in this case, fish), counting them accurately might require more specialized techniques.
Here’s an approach you might consider:
1. Object Detection: Use the object detection techniques you’ve been working with to identify fish in the video stream. This would involve the use of YOLO, SSD, or similar models to detect and label fish.
2. Tracking: Implement a tracking algorithm to keep track of individual fish as they move across frames. Various tracking algorithms, like centroid tracking or Kalman filtering, can help maintain identities of different objects (fish) across frames.
3. Counting: Develop a counting mechanism that keeps track of unique identities assigned to each fish. As new fish are detected, assign them unique IDs and update their positions through the tracking mechanism. Then, count the unique IDs to determine the total number of distinct fish detected.
This process requires combining object detection with object tracking and maintaining a system to differentiate between individual fish. It might involve some trial and error to fine-tune the detection and tracking algorithms for accurate counting, especially in complex environments like a pond with multiple fish.
Additionally, the success of this approach might depend on factors such as lighting conditions, water clarity, fish size, and the camera’s positioning. Calibration and adjustments may be needed to account for these variables.
@@SalteeKiller Thank you so very much for putting me on the right path. I'm quite a newbe to python and pycharm, but I will give it my best shot. At least I'm very inspired by your works and reply!!!
Ain't no way you used chatGPT to reply to his comment @SalteeKiller
thank you sir
Thank you for such a simple introduction to detecting objects with OpenCV. It seems like google colab doesn't allow installation of PyObjC. I used "pip3 install PyObj," and every time I landed on the same error, first it said "Warning Discarding" it discards the pyobj wheel and then tries installing multiple versions but leads to the same error. Do you know if colab can be used for this project?
same problem
Google Colab provides a Python environment that allows installing many packages, but it does have some limitations, especially when it comes to certain system-level packages or those requiring direct access to hardware features.
`PyObjC` is a Python-Objective-C bridge, primarily used on macOS. It's unlikely that `PyObjC` would be compatible or even necessary within Google Colab, which runs on Linux environments. If your project relies heavily on `PyObjC`, it might face challenges running on Colab due to the different operating systems and hardware configurations.
Consider exploring alternatives that don't rely on specific macOS functionalities or libraries. If your project requires Mac-specific features, you might need to work on a local macOS environment or a platform that supports macOS-specific libraries. Alternatively, you could explore cloud solutions that provide macOS environments, but these might come with additional costs.
what about the dataset that was used for training and testing or where is it fetching the data from
We are using a pre built model that is already trained.
Thank you for the video and I understand them pretty easily :D but are you using visual studio 2022? I tried to run on it but its always throwing me errors that there's no module named cvlib even though i have installed and uninstalled it multiple times... as for spyder, i can run on it once with the playsound feature then it will throw an error saying Permission denied to access my folder. For videocapture indexing, I tried put '1' but its only showing my statics in my camera so i had to use '0'
i have the same issue
He was using pycharm
hello Im facing the same issue could did you find any solution
It seems like you're encountering multiple issues. Let's tackle them step by step. For the 'no module named cvlib' error, ensure that you've installed the module in the correct Python environment. Sometimes, installations might not sync with the active environment.
Regarding Spyder and the permission denied issue, it could be related to the access permissions of the folder you're working in. Try running Spyder as an administrator or ensuring that the folder has the necessary permissions for read and write operations.
When dealing with VideoCapture indexing, '0' usually represents the default camera, while '1' might refer to an external camera. The 'O' might stand for the camera in a specific OpenCV notation.
please can someone tell me what software is he using !!
This is PyCharm but can also be used in vsCode
nice video. have you ever gotten it to recognize coins and dates on coins?
To see the final output which command is run on terminal...?
hey, i have the same struggle with you, have you find out how to see the final output???
use this while not keyboard.is_pressed('q'):
how can i do this for an image
So the four loops that we did in the video is for using multiple images inside the video. So you have to do is take out the four loop, then by doing so it will just be doing one image. Then when you select a video source index zero or one or whatever, instead of doing, the indexing, just put in the path of your image
7:50
Here's a simple example of how you might load an image with OpenCV and perform object detection:
```python
import cv2 as cv
# Load the image
image = cv.imread('path_to_your_image.jpg')
# Perform object detection
result = cv.detect_common_objects(image)
# Check the result
if result and 'objects' in result:
for obj in result['objects']:
print(obj)
else:
print("No objects detected or an issue with the image.")
```
Make sure to replace `'path_to_your_image.jpg'` with the actual path to your image file. This code snippet will load the image, perform object detection using `cv.detect_common_objects()`, and print the detected objects. If the image loading process or the result is 'None', it might lead to the error you've encountered.
but it is showing an attributeerror that cv2 module has no attribute called detect_common_objects
Oh no! The `detect_common_objects` method is a part of the `cvlib` library, not directly within OpenCV (`cv2`). When you mentioned the error with 'no module named cvlib', it seems that the `cvlib` library might not have been correctly installed or imported in your code.
Ensure that you've installed `cvlib` via pip: `pip install cvlib`. Then, in your Python script, make sure to import it correctly:
```python
import cv2
import cvlib as cv
# Your code
# Example usage of detect_common_objects method
image = cv2.imread('your_image.jpg')
bbox, label, conf = cv.detect_common_objects(image)
```
If the error persists even after installing and importing `cvlib` correctly, it might be worth checking the version compatibility of the installed libraries. Sometimes, conflicts between different library versions could cause such attribute errors.
@@SalteeKiller Thank you for the reply but when i installed and imported cvlib and used detect_common_objects from cvlib it still shows cvlib does not have an attribute called detect_commopn_objects. i will post my code below
import cv2
import cvlib as cv
image = cv2.imread('D:\pythonProject1\cars.jpeg')
result = cv.detect_common_objects(image)
if result and 'objects' in result:
for obj in result['objects']:
print(obj)
else:
print("No objects detected or an issue with the image.")
is this way could work even with water images?
Bravo
cool video)
nice video
mantap bang
Why do I feel that I have heard 20 different guys talking with this same voice?
Perhaps we are all AI, getting dressed every day with a new disguise
Too bad it's using tensorflow in the background would love to see a lib that does not use it in the background.
Nice
I hope it worked well for you!
@@SalteeKiller not working sir
Error
I need pdf
im like your 1998 sub
Wow you were so close! ❤️
👍 ᑭᖇOᗰOᔕᗰ
For anyone doing this today/in the future: You can add these 2 lines of code to the bottom of your program if you don’t want the video capture to linger. He didn’t do it in the video.
video.release()
Cv2.destroyAllWindows
1352024
how do i do this for an image?
You can do the image capture variable without the for loop
The error message "Non-type has no attribute 'shape'" typically occurs when you're trying to access the 'shape' attribute of a variable that happens to be 'None' or a non-existent object.
This could happen in the context of object detection if there's an issue with the input image or the output from the `cv.detect_common_objects()` function. It's important to ensure that the image you're passing for object detection is valid and properly loaded before using it with this function.
Make sure you're loading the image correctly and check if the image loading process might be returning 'None' instead of the actual image data. You can also check if the image file path or object itself is properly initialized and accessible.
Here's a simple example of how you might load an image with OpenCV and perform object detection:
```python
import cv2 as cv
# Load the image
image = cv.imread('path_to_your_image.jpg')
# Perform object detection
result = cv.detect_common_objects(image)
# Check the result
if result and 'objects' in result:
for obj in result['objects']:
print(obj)
else:
print("No objects detected or an issue with the image.")
```
Make sure to replace `'path_to_your_image.jpg'` with the actual path to your image file. This code snippet will load the image, perform object detection using `cv.detect_common_objects()`, and print the detected objects. If the image loading process or the result is 'None', it might lead to the error you've encountered.