- Edited
Ever heard the phrase, "It's not what you look at that matters, it's what you see"? This could be the unofficial motto of NDVI cameras. If you're scratching your head, wondering what NDVI stands for, buckle up! We’re diving into the vibrant world of these cameras and their interesting applications.
What is NDVI?
First things first, NDVI stands for Normalized Difference Vegetation Index. It sounds fancy, but it’s really just a smart way to measure plant health. NDVI cameras capture images using visible and near-infrared (NIR) light. Healthy plants reflect more near-infrared light and absorb more visible light, while stressed plants reflect less near-infrared light. By comparing these reflections, NDVI cameras can pinpoint which parts of your field are flourishing and which need a little extra love.
How Does NDVI Work?
Let’s break it down without getting too geeky. Here’s the basic idea:
- Capture: NDVI cameras capture light in both visible (the colors we see) and near-infrared (which we can’t see) wavelengths.
- Calculate: The camera uses a formula to calculate the NDVI value for each pixel in the image. The formula is:
visible = cv2.imread('color-image.png') nir = cv2.imread('nir-image.png') # Only get red color from the BGR frame _, _, band_red = cv2.split(visible) # Allow division by zero np.seterr(divide='ignore', invalid='ignore') diff = nir_frame.astype(float) - band_red.astype(float) sum = nir_frame.astype(float) + band_red.astype(float) ndvi = np.divide(diff, sum)
- Visualize: The NDVI values range from -1 to +1, where higher values indicate healthier vegetation. These values are then visualized in a color-coded map, making it easy to spot healthy areas (usually green) and stressed areas (often red or yellow).
# Visualize using matplotlib import matplotlib.pyplot as plt plt.imshow(ndvi, cmap=plt.cm.RdYlGn) # Map colorbar from 1 to -1 plt.clim(1, -1) plt.colorbar() # Save image with this colormap plt.show()
Where is NDVI Useful in Agriculture?
NDVI cameras are like having a plant whisperer on your team. Here’s how they can revolutionize your farming practices:
- Crop Monitoring: Imagine flying a drone equipped with an NDVI camera over your fields. Within minutes, you have a detailed map showing exactly which areas are thriving and which need attention.
- Irrigation Management: Water is precious, and NDVI helps you use it wisely. By identifying dry or overwatered areas, you can fine-tune your irrigation system to ensure every plant gets the right amount of water.
- Fertilizer Optimization: Over-fertilizing can be as bad as under-fertilizing. NDVI cameras help you apply fertilizers precisely where they’re needed, reducing waste and improving crop yield.
- Pest and Disease Detection: Early detection of pests and diseases can save your crops. NDVI cameras can spot stress in plants before it’s visible to the naked eye, allowing for timely intervention.
Hardware for NDVI camera
For NDVI perception you need color and NIR perception. I'll present two options which have their pros and cons.
Single sensor, switchable IR filter
Our OAK Modular lineup is quite flexible - you can easily connect various camera modules to it and it works out of the box. One of the supported camera modules is also the Arducam's IMX477 with switchable IR filter.
With a small modification (soldering FSIN signal on cable adapter to IR filter pin on the camera), we're able to control the IR filter from the Script node with a GPIO.
So if the GPIO was set to 1, the camera would only see visible light. If the GPIO is set to 0, the camera will only see the NIR spectrum. When the camera isn't moving the NIR and visible frames are perfectly aligned, which can save some headaches, especially at close range. The downside is that the IMX477 camera sensor has a Bayer filter, which allows it to "see" colors, but also absorbs some light so quantum efficiency is lower (compared to no Bayer filter / monochrome sensor).script = pipeline.create(dai.node.Script) script.setScript(""" import GPIO MX_PIN = 40 # OAK-FFC-4P R5 toggleVal = True GPIO.setup(MX_PIN, GPIO.OUT, GPIO.PULL_DOWN) GPIO.write(MX_PIN, toggleVal) while True: data = node.io['in'].get() node.warn('GPIO toggle: ' + str(toggleVal)) toggleVal = not toggleVal GPIO.write(MX_PIN, toggleVal) """)
We made a short script here that lets you switch the IR filter and save the frames, so you can later analyze them.Multi-sensor approach
A few of our customers also went with multi-sensor approach, so one sensor for color perception and one sensor for NIR perception. The upside here is that sensors can be hardware synchronized, which means you can have synced NIR and color frames even when the camera is moving.
The downside is that these frames aren't perfectly aligned. You can mitigate this by having the sensors physically close to each other and by moving them further away from the plants we are monitoring.
Another option is to use the ImageAlign node, which can align streams from two different sensors if you know depth plane (distance to crops).
You can follow our Replacing CCMs guide to replace a CCM with IR-cut filter with an NoIR filter (CCM here), which will let you perceive visible + NIR light.
Have comments or questions?
Feel free to comment below, or send us an email at support@luxonis.com!