Author Topic: A simple tool to aid in reverse engineering a PCB  (Read 11876 times)

0 Members and 2 Guests are viewing this topic.

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3798
  • Country: de
Re: A simple tool to aid in reverse engineering a PCB
« Reply #25 on: December 01, 2018, 05:35:05 pm »
Simon I have done a lot of camera calibrations on phones (it is necessary for doing any kind of computer vision/augmented reality) and they really don't distort that much, even at full wide setting. We aren't talking early 2000 camera phones anymore. For example iPhone/iPad cameras gave me a calibration that was pretty much dead on match to an ideal pinhole camera. Square pixels, distortion coefficients down in the noise. I am sure the physical camera isn't so great and Apple's firmware does some undistortion/pre-processing before delivering the image to the userland APIs (I am not talking about the camera app but images grabbed from the camera using my own code) but the user doesn't really care about that.

SLR lenses often distort much more than tiny smartphone lenses, especially barrel distortion at the wide end can be really pronounced. The smartphone lenses with their microscopic focal length don't really have where to pick that kind of distortion up at the distances the lens is usually being used (and is even able to focus). It is extremely difficult to build anything resembling a fisheye in such small form factor. That doesn't mean it is impossible to build a crappy lens but given the smartphone prices today the customers would lynch such company.

Of course there is no comparison with an SLR when it comes to sharpness, color aberrations and minimal aperture/low light capabilities but you really don't care about any of that when shooting pictures of PCBs for analysis. For this kind of job an SLR is an enormous overkill, even a crappy handheld phone shot is going to be usable just fine. The idea is to enable reverse engineering boards, not to win a photography contest! (and yes, I do own a Canon 80D with a few lenses too)

Also often when you are fixing boards you don't have an SLR at hand but almost everyone has a phone - then the whole point is moot.

Anyway, if you happen to have a phone that produces images so distorted that it would cause problems with the reverse engineering, it is pretty simple to calibrate the camera and remove the distortion in software after the fact. Definitely simpler than having to monkey around with a large camera, tripod and what not - and have to undistort the image anyway ...




« Last Edit: December 01, 2018, 05:50:00 pm by janoc »
 

Offline intabitsTopic starter

  • Frequent Contributor
  • **
  • Posts: 319
  • Country: au
Re: A simple tool to aid in reverse engineering a PCB
« Reply #26 on: December 01, 2018, 06:19:33 pm »
A better solution is to get rid of the tripod (so that you can use a phone instead of a camera/scanner that may not be on hand, find a good angle where you don't have glare, etc.) and instead find 4 points that you know the position on the board (e.g. 4 corners). Then you can warp the image to get rid of any trapezoidal distortion due to the camera not being exactly perpendicular with the board. In theory this could be done with any 4 points (they don't have to be right angle corners but those are the simplest) automatically - it is called finding a homography transform.
.....
The layer alignment can be done in a similar way - first rectify the images up as above and then you can find a transform between matching points that will scale and align one layer over the other one. All that this needs is solving a system of linear equations.
Yes, you could complicate a simple program with fancy algorithms and maths, to avoid using a tripod. Or, use a tripod. Or any arrangement of blocks of wood, rubber bands and blu-tack that will enable you to take two photos without moving the camera. 
Sure, you'd have all that fancy stuff in a full-featured program, but it's not an essential feature. There's other higher value core functionality that I would be adding long before that.

Quote
A few other features I have found useful or wished to have:
- filling the traces with color so that you can easily see the individual nets
- marking of the components and their pins
- have a way to generate a netlist/rough schematic out of the above - e.g. this could be perfectly doable with KiCAD where the schematic is just a large text file.
I mentioned earlier that the component/pin marking and netlist generation was a desirable future direction.
That's where I would be adding complexity...
 

Offline intabitsTopic starter

  • Frequent Contributor
  • **
  • Posts: 319
  • Country: au
Re: A simple tool to aid in reverse engineering a PCB
« Reply #27 on: December 02, 2018, 06:55:44 am »
...Then you can warp the image to get rid of any trapezoidal distortion due to the camera not being exactly perpendicular with the board. ...it is called finding a homography transform.
I've just played with a much more demanding example: a 275mm x 290mm double sided PCB with 100 chips on it.
And with that, the distortion was too great, even with careful use of a tripod.
I added pan and zoom, and then X/Y shift adjustments, but any given adjustment setting was good for only a small area, maybe 50mm square.

So I accept that homography would be absolutely necessary for images like that. But I maintain that the other functions for marking pads and connections are still much more important. You'd want those facilities for all but the simplest PCBs, whereas you could probably get onto fairly complex PCBs without needing homography.

Of course, trying to reverse engineer a large PCB like the one I mentioned above would be a massive task, no matter how sophisticated the tools being used.
And might still be nigh on impossible...
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17838
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: A simple tool to aid in reverse engineering a PCB
« Reply #28 on: December 02, 2018, 08:57:16 am »
Simon I have done a lot of camera calibrations on phones (it is necessary for doing any kind of computer vision/augmented reality) and they really don't distort that much, even at full wide setting.

I just examined pictures taken of mysely and some friends, one on my SLR one on a camera phone. The people to the edge of the phone picture start to distort. Not enough for you to notice unless you make a comparison. Fortunately PCB's don't care if they look fat :)
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3798
  • Country: de
Re: A simple tool to aid in reverse engineering a PCB
« Reply #29 on: December 02, 2018, 10:30:06 am »
Yes, you could complicate a simple program with fancy algorithms and maths, to avoid using a tripod. Or, use a tripod. Or any arrangement of blocks of wood, rubber bands and blu-tack that will enable you to take two photos without moving the camera. 
Sure, you'd have all that fancy stuff in a full-featured program, but it's not an essential feature. There's other higher value core functionality that I would be adding long before that.

If you call a set of linear equations "fancy math", I don't know what to say.

The issue is usability of the program. If I can click 4 corners and have the image fixed up vs. having to set up a tripod, prop up the board so that it sits level even if there are components on the bottom and still will have a distortion because the board isn't on the axis of the lens and isn't perfectly perpendicular, the former is a big win for me.

But you are free to do as you wish, of course.
 

Offline cdev

  • Super Contributor
  • ***
  • !
  • Posts: 7350
  • Country: 00
Re: A simple tool to aid in reverse engineering a PCB
« Reply #30 on: December 03, 2018, 02:51:23 am »
This free program is really two programs, enblend and enfuse that can turn multiple images into one and hide the seams for you. It does a really good job of it. They work great with images taken with the intention of emulating a scanner - for example, large photos of books or maps or PCBs. And of course you can use it to stitch several small scans with your small a4 or letter or legal size size scanner together to make big scans.

http://enblend.sourceforge.net/

Combine it with "hugin" (and at least one flavor of "sift" which I am sure at least you janoc are already familiar with) and you'll have a complete panorama workbench which can be used to do all sorts of things with multiple images including all sorts of perspective transformations and mappings.

http://hugin.sourceforge.net/

Its ideal for stitching images of any kind and coming out of the process with a square image with accurate sizes, with a little tweaking.

A flatbed scanner's scans sizes are based on the math of the x-y scanning process with its two stepper motors so usually are very close to being pixel accurate/ verifiably right.
« Last Edit: December 03, 2018, 08:03:33 pm by cdev »
"What the large print giveth, the small print taketh away."
 

Offline orbanp

  • Regular Contributor
  • *
  • Posts: 168
Re: A simple tool to aid in reverse engineering a PCB
« Reply #31 on: December 07, 2018, 12:46:01 pm »
This program is very useful as it is!

It would be great if you could save the combined image, and if it would handle png files as well.

Thanks for making this available!

Regards, Peter
« Last Edit: December 07, 2018, 12:49:06 pm by orbanp »
 

Offline cdev

  • Super Contributor
  • ***
  • !
  • Posts: 7350
  • Country: 00
Re: A simple tool to aid in reverse engineering a PCB
« Reply #32 on: December 07, 2018, 03:21:08 pm »
This program is very useful as it is!

It would be great if you could save the combined image, and if it would handle png files as well.

Thanks for making this available!

Regards, Peter

I am not the author! Just a photographer who has been using enblend/enfuse for a long time for photos of stuff.

Hugin is great too!

You know, image recognition has come so very far in the last few years, we really are not very far away from a automated program that could literally suck in two good quality photos of both sides (of a two sided PCB) and/or perhaps some backlit trans-illuminated images to reveal its internal trace structure - that would be needed if it was a multi layer board-

A program that could take your hi-res photos of a PCB and generate a schematic from that automatically, labeling any questionable areas and perhaps suggesting measurements - taken at specific points - which it could also suggest - that could resolve ambiguities.

It might even be able to guess as to unknown values and suggest what the device's function might be.

 

« Last Edit: December 07, 2018, 03:23:21 pm by cdev »
"What the large print giveth, the small print taketh away."
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf