Lens swap - what to look for when selecting an aftermarket lens

Malvineous

Getting the hang of it
Joined
Jan 7, 2023
Messages
35
Reaction score
33
Location
Brisbane, Australia
Hi all,

I have just purchased a DH-IPC-HFW3866EP-AS-AUS (8MP bullet non-PTZ) with the intention of swapping the lens for a wide angle one. This is mostly because Dahua don't sell a camera (at a reasonable price) with the lens that I want (at least 170 degrees horizontal view, 90+ degrees vertical).

So my plan is to see if I can get an aftermarket lens and put it in this camera. The camera specs say it takes an M12 lens, and there are plenty of these available, however I'm not exactly sure what I'm after.

Some lenses say they are 5MP, 8MP, or 12MP - does this matter? Do I need to get a lens matching the same or more pixels than the camera sensor? Is this because of the lens clarity or something else? I assumed all lenses were analogue/optical so the MP rating wouldn't matter, so I'm not sure why they put a MP rating on the lens at all.

Lenses also seem to be for different sized sensors, even though they are all M12. Some say they are 1/2.7", or 1/3.2", etc. The Dahua camera I bought says it has a 1/2.8" sensor, so does that mean if I get a lens with a different size, I will get either a black border around the edge of the picture, or it will appear zoomed in further than the lens' viewing angle suggests?

On that note, some of the screenshots on the lens sale listings show a fisheye view (circle in the camera image with lots of black around the outside). I don't want to "lose" pixels by having so many black ones around the edge, so should I be looking for a lens that's larger than the camera's 1/2.8" and consequently with a wider viewing angle than I need, in order to both fill up the frame and get the viewing angle I'm after?

Lastly, some lenses are sold with or without an IR filter. I assume I want one without the IR filter so that IR/nightvision works, but it would be great if someone could confirm in case I am misunderstanding what this IR filter is for.

Has anyone tried swapping a lens before in their Dahua camera, and if so how did it go? It looks like with this camera I'll have to remove the thin transparent plastic window in front of the lens in order to fit a wide angle lens there (because the lens is bulbous and needs to stick out much further than the factory lens), so I'm curious how others have gone with this procedure as I imagine I'm not the first to try it.
 

CanCuba

Known around here
Joined
Dec 9, 2020
Messages
1,132
Reaction score
3,418
Location
Havana, Cuba
Hi all,

I have just purchased a DH-IPC-HFW3866EP-AS-AUS (8MP bullet non-PTZ) with the intention of swapping the lens for a wide angle one. This is mostly because Dahua don't sell a camera (at a reasonable price) with the lens that I want (at least 170 degrees horizontal view, 90+ degrees vertical).

So my plan is to see if I can get an aftermarket lens and put it in this camera. The camera specs say it takes an M12 lens, and there are plenty of these available, however I'm not exactly sure what I'm after.

Some lenses say they are 5MP, 8MP, or 12MP - does this matter? Do I need to get a lens matching the same or more pixels than the camera sensor? Is this because of the lens clarity or something else? I assumed all lenses were analogue/optical so the MP rating wouldn't matter, so I'm not sure why they put a MP rating on the lens at all.

Lenses also seem to be for different sized sensors, even though they are all M12. Some say they are 1/2.7", or 1/3.2", etc. The Dahua camera I bought says it has a 1/2.8" sensor, so does that mean if I get a lens with a different size, I will get either a black border around the edge of the picture, or it will appear zoomed in further than the lens' viewing angle suggests?

On that note, some of the screenshots on the lens sale listings show a fisheye view (circle in the camera image with lots of black around the outside). I don't want to "lose" pixels by having so many black ones around the edge, so should I be looking for a lens that's larger than the camera's 1/2.8" and consequently with a wider viewing angle than I need, in order to both fill up the frame and get the viewing angle I'm after?

Lastly, some lenses are sold with or without an IR filter. I assume I want one without the IR filter so that IR/nightvision works, but it would be great if someone could confirm in case I am misunderstanding what this IR filter is for.

Has anyone tried swapping a lens before in their Dahua camera, and if so how did it go? It looks like with this camera I'll have to remove the thin transparent plastic window in front of the lens in order to fit a wide angle lens there (because the lens is bulbous and needs to stick out much further than the factory lens), so I'm curious how others have gone with this procedure as I imagine I'm not the first to try it.
I've swapped out a couple M12 lenses. They're cheap and easy to replace. Hardest part is getting the glue off the thread of the existing lens (I use the tip of a box cutter blade) and then focusing the new lens. It's a fine thread so it's a bit hard to not crossthread it and then it's a number of revolutions before you start to get close to focus. I detailed swapping a 2.8mm lens for a 25mm lens in a Dahua 3421 variant here.

I get my lenses off of Amazon but AliExpress had a tonne more selection. To answer your questions:

1) MP rating: It does matter but it's not absolutely critical as in "make it or break it" when it comes to the lens swap. The MP rating represents, roughly, the quality of the lens. Put in an equivalent MP lens or higher. Since your camera is 8 MP, you may have less of a selection.

2) Sensor size rating: This matters. Match the sensor size for the best results. If you get a lens for a smaller sensor (1/3", for example), you will have black in the edges of the images. If you go larger (1/2.7" or 1.2"), you'll lose part of the image as it won't all be projected onto the sensor.

3) Yes, get one without an IR filter. This is the least difficult spec to match when buying a lens.

When disassembling the camera, be patient and take pictures as you go. You probably need to start by removing the plastic piece on the front of the camera to expose the hex screws. Then take those off and see what you're up against. You'll probably need to do some further disassembly. Be gentle with the ribbon cable. Best to disconnect it from one end. Easy to disconnect but can be a bitch to reconnect.

Try to do this in as clean an environment as possible. Avoid being around moving air. The most critical moment is when you remove the existing lens and thread the new lens on. Have the new lens at hand so you minimize the time the sensor is exposed to any dust. You don't want dust on the sensor.

If you run into problems, reply in this thread (best) or PM me. Replying in the thread will get you access to others who have done this before.

Best of luck!
 

CanCuba

Known around here
Joined
Dec 9, 2020
Messages
1,132
Reaction score
3,418
Location
Havana, Cuba
Here's a 1.8mm 8MP 1/2.8" lens. Comes with or without IR filter. Only has a horizontal angle of 123 and vertical angle of 86 degrees. It does have an f-stop quite a bit more than the factory lens (f 1.4) so you'll have issues with light.


This is your best bet from a quick search. There are other sites that sell M12 lenses with great specs but you'll be paying quite a bit more. Like around $50 USD for a lens.
 

CanCuba

Known around here
Joined
Dec 9, 2020
Messages
1,132
Reaction score
3,418
Location
Havana, Cuba
This will get you 150 degrees horizontal. But it's listed for a webcam so I doubt the lens is great quality.

 

Malvineous

Getting the hang of it
Joined
Jan 7, 2023
Messages
35
Reaction score
33
Location
Brisbane, Australia
Very interesting! Thanks for all the info, that helps a lot. Taking the camera apart doesn't worry me as I've already done it a few times to solder on UART connectors so that's all good.

I did find that 1.8mm lens you linked to, but in the specs it says "maximum image circle: 7mm" and if I convert the 1/2.8" sensor value to mm it comes out as 9.07mm. So doesn't this mean the lens will project a 7mm diameter circle onto a 9mm diagonal square? Presumably that would result in black around the edges, which is why I was thinking maybe I have to aim for a lens that offers a larger sensor size, if I don't want black around the edges of the image. In your thread you chose a lens that matched exactly and didn't seem to get any black around the edges so in that case I'm not quite sure how the circle projection size relates to the sensor size.

I found a 12MP 1/2.7" 160-degree lens that says it projects a 9.2mm circle at 160 degree diagonal angle, which suggests it would cover the whole sensor. The horizontal angle isn't as wide as I'd like but the vertical is good.

There's also an 8MP 1/2.7" 210-degree lens but it doesn't have any specs so not sure what the projection circle size is. I wonder if they are all the same for everything listed as 1/2.7"? Same for this 8MP 1/2.7" 185-degree one.
 

Gimmons

Getting comfortable
Joined
Jan 7, 2022
Messages
173
Reaction score
276
Location
California
Last year, I set up seven m12-lens board cameras from ebay for a church streaming system. To get the right views, I bought a bunch of m12 lenses in different focal lengths and did trial and error until I got what was best. So I'd suggest the following:
1. M12 lenses are generally cheap, so buy a bunch in varying focal lengths and start trying them. If your housing is big enough, you can get zoom lenses. If you have space, you can also use c and cs-mount lenses using an m12 to c- mount adapter.
2. Don't worry about the MP rating. Get your focal length dialed in first. Once you're happy with the view you're getting, then you can get a better lens if needed. I suspect the mp numbers are hype, anyway.
3. Don't worry about whether the image circle will cover the sensor in advance. If you're getting too much tunnel on a long lens, you can try a wider one.

One test is worth a thousand theories.
 

CanCuba

Known around here
Joined
Dec 9, 2020
Messages
1,132
Reaction score
3,418
Location
Havana, Cuba
Very interesting! Thanks for all the info, that helps a lot. Taking the camera apart doesn't worry me as I've already done it a few times to solder on UART connectors so that's all good.

I did find that 1.8mm lens you linked to, but in the specs it says "maximum image circle: 7mm" and if I convert the 1/2.8" sensor value to mm it comes out as 9.07mm. So doesn't this mean the lens will project a 7mm diameter circle onto a 9mm diagonal square? Presumably that would result in black around the edges, which is why I was thinking maybe I have to aim for a lens that offers a larger sensor size, if I don't want black around the edges of the image. In your thread you chose a lens that matched exactly and didn't seem to get any black around the edges so in that case I'm not quite sure how the circle projection size relates to the sensor size.

I found a 12MP 1/2.7" 160-degree lens that says it projects a 9.2mm circle at 160 degree diagonal angle, which suggests it would cover the whole sensor. The horizontal angle isn't as wide as I'd like but the vertical is good.

There's also an 8MP 1/2.7" 210-degree lens but it doesn't have any specs so not sure what the projection circle size is. I wonder if they are all the same for everything listed as 1/2.7"? Same for this 8MP 1/2.7" 185-degree one.
I've never seen the image circle metric before the listing in question. I doubt it would make much of a difference as everything else I've seen is sized for the sensor.

As @Gimmons points out, these things are cheap. I have a half dozen in a little baggie ready to be put in a camera at any time.

In my BoobieCam project (still to be mounted), I swapped out the 3.6mm lenses for a 6mm and 8mm lens. As 12mm was too much for the sensor that I mount 8mm on, I used a lens for a larger sensor (sensor is 1/2.7", I use a 1/2.5") to get a tighter field of view without going to 12mm. I can't wait to get that camera mounted and running. Been fun planning the project but haven't had time to install the camera yet.
 

Malvineous

Getting the hang of it
Joined
Jan 7, 2023
Messages
35
Reaction score
33
Location
Brisbane, Australia
Well the lenses arrived but unfortunately as I suspected it wasn't so simple - they don't work with the camera. Although they are both M12, only one of them screws into the camera, the other one gets a couple of turns in and then won't budge, so it seems there are two variants of M12 with ever so slightly different tolerances. The lens that would not screw in was the 8MP 185° 1.3mm F2.0 1/2.7".

The lens that did screw in - a 8MP 210° 1.05mm F2.2 1/2.7" - got stuck on a protruding plastic section, so it wouldn't go in far enough:

dahua-lens_swap1.jpg dahua-lens_swap2.jpg

So I cut away enough of the plastic for the lens to fit, and I was able to screw it in further:

dahua-lens_swap3.jpg

Unfortunately this still wasn't enough - the lens screwed in as far as it could go (the lens had more thread on it but it hit the internal glass shield over the image sensor). So all I got was a blurry circle with nothing in focus.

I'm not sure which part of the specifications I need to look at to figure out why these lenses didn't work, so if anyone has any ideas let me know. It seems to be that the lenses must be able to work with a larger distance between the end of the lens and the sensor surface.

EDIT: I found the original lens that came with the camera - 8MP 128° 2.8mm F1.6 2/7" which has a lot of detailed specs, so I guess I need to find a lens with similar 'back focal length' parameters.
 
Last edited:

Malvineous

Getting the hang of it
Joined
Jan 7, 2023
Messages
35
Reaction score
33
Location
Brisbane, Australia
Before and after what? The removal of the plastic bracket? There's barely any difference, the lens has to screw in way further before you can see anything. It's not just blurry, all you can see on the video are just a couple of large colour blobs.

After doing more research, it looks like the lens that fit requires a 3mm gap between the back of the lens and the sensor, whereas the factory lens has a 5-6mm gap. So the wide angle lens has to screw in much closer to the sensor than the factory lens but that's not mechanically possible.

I managed to find another wide angle lens with a similar 5-6mm "back focal distance" so hopefully that one will do the trick when it arrives. They are difficult to find as it's buried in the specs so you have to open the listing for every single lens, and even then not all sellers list the full specs so it takes a while to find one that fits your requirements.
 

duplo

Getting comfortable
Joined
May 26, 2022
Messages
301
Reaction score
376
Location
Berlin, Deutschland
Before and after what? The removal of the plastic bracket? There's barely any difference, the lens has to screw in way further before you can see anything. It's not just blurry, all you can see on the video are just a couple of large colour blobs.
original lens and new lens , what else.

picture from actual live view, not a picture from the camera with lens screwed in
 

Perimeter

Getting comfortable
Joined
Feb 18, 2023
Messages
557
Reaction score
581
Location
Europe
I'm not sure which part of the specifications I need to look at to figure out why these lenses didn't work, so if anyone has any ideas let me know. It seems to be that the lenses must be able to work with a larger distance between the end of the lens and the sensor surface.
If you have a lens with focal length f, it will normally focus to infinity when the lens is f away from the sensor. So wide angles (low f) would require very close distances to the sensor, like 1.05mm. Back in the days of SLR photography, that was not an option, as the mirror assembly took up several centimeters. So these lenses had some add on lenses to extend the infinity-convergence point further backward, allowing the lens to be mounted in front of the mirror. Which is basically what you describe too.

By the way, I get a "page not found" when checking you link to the original lens.
 
Last edited:

duplo

Getting comfortable
Joined
May 26, 2022
Messages
301
Reaction score
376
Location
Berlin, Deutschland
By the way, I get a "page not found" when checking you link to the original lens.
Most sellers on aliexpress dont sell to france and germany because they have stupid recycle laws. So aliexpress is blocking these products for german/france IPs.

 

Malvineous

Getting the hang of it
Joined
Jan 7, 2023
Messages
35
Reaction score
33
Location
Brisbane, Australia
original lens and new lens , what else.
Sorry, I thought why would you be asking for that when I already explained what it looked like. You can't see anything, it's just colour blotches. It's like the lens is out of focus a million times worse than normal. If you take a photo and resize it to 3x3 pixels then enlarge it back to normal size (with pixel smoothing enabled), that's what you see in the camera's video feed. I didn't bother taking a screenshot with the lens in place because there's nothing to see.

If you have a lens with focal length f, it will normally focus to infinity when the lens is f away from the sensor. So wide angles (low f) would require very close distances to the sensor, like 1.05mm. Back in the days of SLR photography, that was not an option, as the mirror assembly took up several centimeters. So these lenses had some add on lenses to extend the infinity-convergence point further backward, allowing the lens to be mounted in front of the mirror. Which is basically what you describe too.

By the way, I get a "page not found" when checking you link to the original lens.
That would explain why you can get wide angle lenses with different "back focus length" values. Some are 3mm, quite a few are 4mm, and the one I bought to try is 5.5mm. So they no doubt have extra lens elements to extend this value.

The AliExpress link I posted definitely works from here in Australia. I will embed the relevant parts of the listing here. As a reminder, this is the original factory lens that came with the DH-IPC-HFW3866EP-AS-AUS:

orig-lens.png orig-lens-diagram.png orig-lens-photo.jpg orig-lens-photo2.jpg

You can see in the bit marked 5.2.2 "Viewpoint Figure" there is a part labelled "image plane" which is where the image sensor must be. There is a "5.27 (in air)" measurement, which shows the sensor must sit 5.27mm away from the back of the lens. In the table of values, this is the "mechanical back focal length" (the distance from the sensor to the end of the lens, measured up to the plastic part of the lens). They also have the "optical back focal length" which is slightly longer because it goes past the lens plastic housing and up to the actual lens glass.
 

Perimeter

Getting comfortable
Joined
Feb 18, 2023
Messages
557
Reaction score
581
Location
Europe
I have invested roughly $13 on a telephoto lens. If it turns out not to work in the camera, I will book it as tuition fee.

The interesting question for me is, how do I find the distance my camera requires. What documents did you use and how did you find them?
 

Malvineous

Getting the hang of it
Joined
Jan 7, 2023
Messages
35
Reaction score
33
Location
Brisbane, Australia
I didn't use any documents, I just bought two lenses to try, one didn't fit and the other didn't give a picture. So then I investigated and as I was searching I just happened by chance to find an AliExpress listing for the original lens, which has a very distinctive look to it. That listing had all the specs for it, so I bought another one closer to those specs. I won't know if it's correct until it arrives and I try it.

I guess if you remove your lens first and try to find the specs on it it could help. I imagine if you held the lens up to a bright scene and tried to get it to focus an image onto a piece of paper, you could also measure the distance between the lens and the paper when it is projecting a perfectly focused image onto the paper? But given that you're looking at a difference of millimetres you'd have to be pretty precise with your measurements.

I do wonder whether cameras with similar sized sensors would use similar lenses though. If your telephoto lens works and you can find out the back focal length, let us know (that and the camera model so we can see the sensor size) just to see if there is any pattern.
 

Perimeter

Getting comfortable
Joined
Feb 18, 2023
Messages
557
Reaction score
581
Location
Europe
I do wonder whether cameras with similar sized sensors would use similar lenses though. If your telephoto lens works and you can find out the back focal length, let us know (that and the camera model so we can see the sensor size) just to see if there is any pattern.
I could imagine that the IR filter will take up space and require more distance. So even with the same sensor size, some may not require extra distance (LED vs IR perhaps).
I will report back once I get the stuff working or not.

I imagine if you held the lens up to a bright scene and tried to get it to focus an image onto a piece of paper, you could also measure the distance between the lens and the paper when it is projecting a perfectly focused image onto the paper?
Yes. Just make sure you use something further away.
 

Malvineous

Getting the hang of it
Joined
Jan 7, 2023
Messages
35
Reaction score
33
Location
Brisbane, Australia
That's very true, I guess it depends on whether they keep the same housing if they have an IR filter or not. It might be cheaper to keep the same distance to the sensor so they can use the same model lens across as many different camera models as possible.
 

Malvineous

Getting the hang of it
Joined
Jan 7, 2023
Messages
35
Reaction score
33
Location
Brisbane, Australia
The next lens I purchased just arrived. This one has a larger 'back focal' length and it is indeed compatible with the camera. Here are some framegrabs showing the original lens that came with the HFW3866EP camera compared to the new wide angle lens.

Original factory lens for comparison:
dahua-hfw3866ep-factory-0.35in-2.8mm.jpg (click thumbnail for original resolution)
dahua-hfw3866ep-factory-0.35in-2.8mm.thumb.jpg

New wide angle lens:
dahua-hfw3866ep-0.55in-1.85mm.jpg (click thumbnail for original resolution)
dahua-hfw3866ep-0.55in-1.85mm.thumb.jpg

The new lens was listed on Aliexpress as "12 Megapixel 1.85Mm Lens Wide Angle 185 Degree 1/1.7Inch F2.0 M12 Mount 12Mp Ir Fisheye Lens For Security Ahd Tvi Cvi Ip Camera". Although it says 1/1.7" in the title it says 1/1.8" in the photo and on the lens itself. Despite this, you can see there are still some black areas in the corners even though the camera has a smaller 1/2.8" sensor, so I guess if you had a 1/1.8" you would fit the whole fisheye circle on the lens, at the expense of a lot of unused pixels (which seems correct as the lens specs say the vertical angle is only as large as 185° on a 1/1.7" sensor, and reduced to 126° on a 1/2.5" sensor which is close to this camera's 1/2.7" sensor). In my case I wanted to fill up the frame as much as possible so I'm quite happy with it - I can live with the small black areas in the corners of the frame, and the horizontal viewing angle is still 180° which is what I was after.

One drawback of this lens is that the largest glass part sits right where the front of the camera housing goes, so I am not sure whether it will be possible to put the front of the camera back on while having the lens screwed in far enough to be properly in focus. I may have to come up with another solution.

dahua-hfw3866ep-0.55in-1.85mm.face_overlap.jpg
 
Last edited:
Top