Automated Vehicle Plate Recognition

A place for discussion of topics that are not specific to ZoneMinder. This could include Linux, Video4Linux, CCTV cameras or any other topic.
trev-nc
Posts: 6
Joined: Wed Jun 28, 2006 5:13 am
Location: Preston

Automated Vehicle Plate Recognition

Post by trev-nc »

Hi, I'm looking for seveveral Items/ Products and I wonder if you could help or indeed 'if you would wish too' Please allow me to explain;

I'm been contemplating delving into the AVPR (Automated Vehicle plate Recognition) market for a considerably length of time. Unfortunately the setting up costs of both Hardware/ software have been ridiculously high, however things have indeed changed recently and so I do believe the time is right for our company to embark on seeking the latest technology that eliminates bulky installation and running costs !

Who are We?

We are one of the largest vehicle Immobilisers in the UK (On private land), I/we have over 600 Blue chip companies on my client list who have over 2000 sites in 300 town & cities in England & Wales We issue annually 50.000 permits (Decals) per year but we only immobilise 7,000 vehicle and issue a further 3,000 FPN's. Although this might agrovate quite a few readers we really do try to provide good car park management using the threat of fiscal punishment and those penalised really only have them selves to blame!

What are you looking for?

There are numerous 'Intelligent Camera's' on the market that claim they are the biggest / smallest fastest most capable yet less costly but what we really need is one that can be programable or;

A camera with built in /embedded Motion Detector software (Preferably Linux) and with GSM or GPRS capabilities if not USB & RJ45 is fine. Be capable of utilising the web, and or SMS Messaging for low comms cost (I know that Sony produced one but I cannot trace the supplier,,,, as of yet!

The camera using OCR records registration numbers in a specified field, time in and time out and identifies Non permitted Vehicles having checked that particular sites data base and /or vehicles with no time out before the permited time, for example a retail outlet might say 'Free parking for 2 hours' any one who stays overnight is offending!

The camera / cameras located all over the UK will relay photographs of offending vehicles back to my servers in Preston of vehicles entering / leaving car parks under my control that haven't conformed to the restrictions.Vehicles that didn't abide by the allocated time or is not permitted will be classified as an offence! and the server will automatically inform the immobilisers of that offence and request a clamp to be fitted. Should the vehicle leave prior to vehicle immobilisation then we resort to sending a penalty notice through the post having contacted the DVLA for the drivers details!

This is an extremely interesting project and has a lot of Q's not A'd But
If you wish to speak to me in confidence I am available on 01772 882 992 UK Time!

Trevor Whitehouse
Chairman

or Ask for Greg
The IT Boff
Flash_
Posts: 441
Joined: Wed Jan 11, 2006 12:19 pm

Post by Flash_ »

Blimey.

That sounds do-able, but very complicated and will take a lot of tweaking etc. Not sure why you posted here, that doesn't sound like an open-source type of project being as it's very specialised and very commercial in target and you appear to be asking for help for free? (Forgive me if that's not the case, what you're asked is a bit vague) And if so, somewhat cheeky as the only usage for it would be to extract money from people...

If you look at this project on a single installation case (others would simply be a case of copying the technology) then this could easily run to tens of thousands even before the hardware is issued.

By the way, ignore GPS/SMS - just install an adsl link onsite. Very cheap low-bandwidth always-on connection that's fast, secure and reliable. Why incur a per-command cost? This also allows you to operate the cameras/upgrade etc remotely from Preston via vpm/rdc/ssh/whatever.

I've no experience with ocr, someone else here may have some or may know of suitable cameras. Don't forget lighting conditions and positions!
trev-nc
Posts: 6
Joined: Wed Jun 28, 2006 5:13 am
Location: Preston

Post by trev-nc »

Why this forum? Because Zoneminder is half way there with the motion detector and Linux is very stable and very reliable. The people who use linux usually know what there talking about!

And Oooops sorry, I didn’t want to come across as ‘a wee bit cheeky’ although I know I did (a little)! I turned to a forum because I haven’t got a clue which way to turn for the best! So much advice from differing manufactures So by turning to open source, that is people who are unbiased and not giving advice for fiscal gain could point me in the right direction, besides that I presume some of you would like the challenge & what you do with the project afterwards would be your affair I don’t really care Maybe a career with me, perhaps sell it on this site, why not it wouldn’t be mine? Your are right this project could indeed turn into thousands of pounds and I’m certain that I will probably have to spend that in the long run. However it is a thing of the future and I’m quite prepared to ‘Bolt’ things together for now. Should they work then I’ll will invest more, but at the moment its pie in the sky until I convince the Company involved that’s the way to go!

The company concerned really is National (But no names mentioned) I think I could secure probably 1 to 10 branches initially and that’s just on a trial basis! And then it could grow and then I’d take this to other retail outlets.

Any body interested!

http://visl.technion.ac.il/projects/2003w24/

Go right to the very bottom for the open source ocr bit!
jameswilson
Posts: 5111
Joined: Wed Jun 08, 2005 8:07 pm
Location: Midlands UK

Post by jameswilson »

I and others here have looked at adding anpr to zm, but the detection is the difficult bit. Making zm present images to the ocr engine is the easy it. I have looked at the links but the source is not in a language i have an envirenment for so i cant take a peek, I assume its c++ for speed. What you need is a bit custom and you have identified a market for your product. I (as always) would be interested in moving zm forward in any direction, but i think you need someone with the coding ability of Phil for this
James Wilson

Disclaimer: The above is pure theory and may work on a good day with the wind behind it. etc etc.
http://www.securitywarehouse.co.uk
trev-nc
Posts: 6
Joined: Wed Jun 28, 2006 5:13 am
Location: Preston

Post by trev-nc »

I believe your right with C++ the operating system is Matlab ? I can copy and paste the code on this site if its allowed! Is it?
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

It's fine by me if it's ok with the owner of the code. Or start a topic in the Wiki which might have a bit more longevity.
Phil
trev-nc
Posts: 6
Joined: Wed Jun 28, 2006 5:13 am
Location: Preston

Post by trev-nc »

Sorry for the delay but I've been away for a week and just got in. The source was right there, on the bottom of the link that I previously posted, I presume if you place it on the web (call it 'open source') for all to see with no restrictions then so be it ! I doubt if you'd wish to copy it, but its a great starting point! and I think! provides you with all the fundamentals,,, (I'm just a mere bricklayer) originally)) and no programming experience what so ever!


RELATED DOCUMENTATION

* Project report (English) [MS Word - 900 KB][Adobe PDF - 723 KB]
* Images
* Matlab Source Code [ZIP]
* A very useful freeware which permit to test most of the Matlab image processing integrated functions [ZIP]
* Poster [ZIP
trev-nc
Posts: 6
Joined: Wed Jun 28, 2006 5:13 am
Location: Preston

Post by trev-nc »

Does this make any sense ?


/*
cmanpr sample1.cpp
*/

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include "gxsd.h"
#include "gxerr.h"
#include "fxvd4.h"
#include "cmanpr.h"

//set the int property for the module specified by handle
int setintproperty(gxHANDLE handle,const char* propname,int value)
{
char v[256];
itoa(value,v,10);
return gx_setmoduleproperty(handle,propname,v);
}

//get the int property from the module specified by handle
int getintproperty(gxHANDLE handle,const char* propname,int* value)
{
char v[256];
if (!gx_getmoduleproperty(handle,propname,v,256)) return 0;
*value = atoi(v);
return 1;
}

void main(int argc,char *argv[])
{
gxIMAGE image; //gxIMAGE object to recognize
//initialise image
gx_initimage(&image);
//if command line parameter is provided, then it is assumed to be either
// a) the name of the picture file, or
// b) the channel number
if (argc == 2)
{
argv++;
if (isdigit(**argv)) // considered as channel number
{
gxHANDLE hcap; //handle for the fxvd4 module
//open fxvd4 module
if (!gx_openmodule(&hcap,"fxvd4","default")) goto error_ret;
//set the capture settings
if (!setintproperty(hcap,"channel",atoi(*argv))) goto error_ret;
if (!setintproperty(hcap,"format",GX_GRAY)) goto error_ret;
if (!setintproperty(hcap,"xres",50)) goto error_ret;
if (!setintproperty(hcap,"yres",50)) goto error_ret;
if (!setintproperty(hcap,"sline",0)) goto error_ret;

//capture an image
if (!gx_capture(hcap,&image,0))
{
gx_closehandle(&hcap);
goto error_ret;
}
//close fxvd4 module
gx_closehandle(&hcap);
}
else // possible the name of a file
{
if (!gx_loadimage(&image,*argv,0)) goto error_ret;
}
{
gxHANDLE hanpr; //handle for the cmanpr module
cmNP* result; //recognized number plate results
char anprname[256]=""; //the name of the engine
int nplate = 0;
//open cmanpr module
if (!gx_openmodule(&hanpr,"cmanpr","")) goto error_ret;
if (!gx_getmoduleproperty(hanpr,"anprname",anprname,256)) goto error_ret;
if (strcmp(anprname,"")) printf("Name of the anpr module: %s\n\n",anprname);
else
{
printf("No engine installed.\n");
gx_closehandle(&hanpr);
goto end;
}
//read number plates from the image
result = 0;
nplate = 0;
if (!cm_findfirst(hanpr,&image,&result)) goto error_ret;
while(result)
{
printf("Found plate: %s\n",result->text?result->text:"No plate text");
//write the position of the frame of the plate
printf("Frame of the plate: (%3i,%3i) - (%3i,%3i)\n",result->frame.x1,result->frame.y1,result->frame.x2,result->frame.y2);
printf(" | | \n");
printf(" (%3i,%3i) - (%3i,%3i)\n",result->frame.x4,result->frame.y4,result->frame.x3,result->frame.y3);
//the application must free the result structure
gx_globalfree(result);
result = 0;
nplate ++;
if (!cm_findnext(hanpr,&result)) goto error_ret;
}
if (nplate == 0) printf("No plate found.\n");
//close cmanpr module
gx_closehandle(&hanpr);
}
goto end;
error_ret:
{
char errmsg[256]; //error message
int error; //error code
gx_geterror(&error,errmsg,256); //obtain error message
printf("ErrorCode: 0x%08x - %s\n",error,errmsg);
}
}
else
{
printf("usage: sample1.exe [channel] or sample1.exe [filename]\n");
}
end:
gx_freeimage(&image);
printf("press any key to exit...");
getch();
printf("\n");
henke
Posts: 60
Joined: Thu Nov 10, 2005 8:16 am

Post by henke »

Hi,

Did you go forward with this? I am also interested in it.

-h
Odin
Posts: 1
Joined: Fri Dec 01, 2006 10:06 am

Post by Odin »

Hi,

I am trying to install Carmen's OCR and I am having lots of problems.

Does anyone know how to install it and can help me with it?

Thank you very much.
jameswilson
Posts: 5111
Joined: Wed Jun 08, 2005 8:07 pm
Location: Midlands UK

Post by jameswilson »

i donbt think it ever went anywhere and there will be a hell of a lot more to it than the code above
James Wilson

Disclaimer: The above is pure theory and may work on a good day with the wind behind it. etc etc.
http://www.securitywarehouse.co.uk
SteveD
Posts: 1
Joined: Tue Dec 12, 2006 12:18 pm

Post by SteveD »

jameswilson wrote:i donbt think it ever went anywhere and there will be a hell of a lot more to it than the code above
I have some experience of ANPR and its a lot more difficult than it sounds - and doesn't work very well with my number plate! (its also not on the DVLA)

I would have thought that one of the biggest issues with any automated system is that of getting sued because of errors, even finding the plate is an issue, never mind reading it.

We got it working eventually but it cost a great deal of money and some very high end equipment

Regards

Steve D

(new ZoneMinder user - well impressed)
User avatar
ammaross
Posts: 61
Joined: Mon Mar 12, 2007 8:34 pm
Location: Utah, USA

Post by ammaross »

trev-nc wrote:Does this make any sense ?
Yes it does. It's a terribly written C++ (actually, just C, but that's another story) program that is an example on how to use their API. Matlab is a scripting environment that specializes in matrices (hence works wonders for images), and can be interfaced with compiled languages (in this case C++).
kenzo_lu
Posts: 1
Joined: Wed May 27, 2009 9:23 am

Post by kenzo_lu »

Hi,

Hello to everyone from this site I am new, this ismy first topic.

Me too I'm working with ANPR ARH for plate recognition and it seems to me some memory leak that happens on my application this due perhaps from the way I use the library of Carmen gx or perhaps of using raw type image file ?

I know that ANPR function can reallocate memory size depending on current analyse images and the application it-self must free after (see documentation of Carmen gx here ):

Code: Select all

Function Documentation
static int cm_findfirst 	( 	struct gxHANDLE  	handle,
		const struct gxIMAGE *  	pimage,
		struct cmNP **  	panprresult	 
	) 			[static]

Reads the first number plate from the image.

By calling the cm_findfirst() function the application can read a number plate from an image. The function returns the character tips of the number plate, and the text of the plate in ASCII and Unicode string format.

Parameters:
    	handle 	The gxHANDLE value retrieved by the gx_openmodule() function of the gxsd module.
    	pimage 	Points to the gxIMAGE structure which contains the image to be scanned for number plates.
    	panprresult 	Points to the cmNP* pointer which receives the data of the number plate found. The pointer value (*pranprresult) is allowed to be NULL or a cmNP* pointer retrieved by a previous call of the cm_findfirst(), cm_findnext() or cm_format() functions.
    In both cases the CMANPR module allocates new memory space for the result if necessary. The application must free this pointer. If the function returns NULL for the *panprresult pointer it means that no plate was found.

Returns:
    On error false is returned and the error code/string in the GX system is set appropriately. ( see gx_geterror() ) 

My application is video-surveillance from which ANPR analyse image files. I Normal process , I use for ANPR analyses only cm_findfirst() and gx_globalfree(anprResult) functions. I'm not using cmd_fidnext() in my program.


My general code squeleton is :

Code: Select all

INIT

 while(1)
 {
  
  PROCESS


 }

DEST


More detailed code INIT is:

Code: Select all



//INIT:

        //variables
	struct gxHANDLE anprHandle;
	struct gxHANDLE imageHandleraw;
	gxMotionDetector* motdet;
	struct gxIMAGE *image;
	struct cmNP *anprResult;
	gxMotionDetectorResult result;


 if(!gx_openmodule(&anprHandle, L"./cmanpr", L"default"))
			return gx_geterror();	

		// Sets a few properties of the ANPR module
if(!gx_setmodulepropertyint(anprHandle, L"contrast_min", contrastMin))
			return gx_geterror();
if(!gx_setmodulepropertyint(anprHandle, L"size_min", plateSizeMin))
			return gx_geterror();
if(!gx_setmodulepropertyint(anprHandle, L"size_max", plateSizeMax))
			return gx_geterror();
if(!gx_setmodulepropertyint(anprHandle, L"gaptospace", GAPTOSPACE))
			return gx_geterror();
if(!gx_setmodulepropertyint(anprHandle, L"timeout", anprTimeout))
			return gx_geterror();
if(!gx_setmodulepropertyint(anprHandle, L"nchar_min", nCharMin))
			return gx_geterror();
if(!gx_setmodulepropertyint(anprHandle, L"depth", depth))
			return gx_geterror();


		if(! gx_openmodule(&imageHandleraw, L"gximage", L"default"))
			return gx_geterror();

	//CREATE MOTION DETECTION
	motdet = new gxMotionDetector("default");
	
	// Sets a few properties of the MOTION DETECTOR
	motdet->SetProperty("xsize", 640);   // Width and height of images
	motdet->SetProperty("ysize", 480);
	motdet->SetProperty("scale_x", 8);   // Diminutives to 44x36
	motdet->SetProperty("scale_y", 8);
	motdet->SetProperty("block_x", 4);   // Block size is 4x4 pixel
	motdet->SetProperty("block_y", 4);
	motdet->SetProperty("contrast_min", 5);  // The minimal contrast is //five in grayscale level
	motdet->SetProperty("sensibility", 10); // The block sensivility for //the area


		if(!gx_allocimage(imageHandleraw, &image))
			return gx_geterror();

		if(!gx_createimage(imageHandleraw, image, GX_GRAY, resX, resY, resX*1))
		{
			return gx_geterror();
		}


More detailed code PROCESS is:

Code: Select all

	bool motionDetected = false;
	int delayms = 0;
	int st = 0;

	//load image from memory
        if(!gx_loadfrommem(imageHandleraw, image, rawImage, imgAllocSize, -1)) 
		return gx_geterror();

	anprResult = 0;

	if(!cm_findfirst(anprHandle, image, &anprResult)) 
		return gx_geterror(); 
	

	delayms = 0;


	if(anprResult)
	{
		// copy output result
		strcpy(Plate, anprResult->text);
		if (confidence) *confidence=anprResult->confidence;

#ifdef _DEBUG
		printf("\n parking_dll: plate found : %s with confidence %d\n", Plate,anprResult->confidence);
#endif

		if(!gx_globalfree(anprResult)) return gx_geterror(); 
			
	}
	else
	{
#ifdef _DEBUG
		printf("\n no plate found\n");
#endif
	}

	motdet->Iteration(image, result);



More detailed code DEST is:

Code: Select all

	// Frees ARH resources	
	gx_freeimage(imageHandleraw, image);

	if(!gx_unrefhandle(&imageHandleraw))
		return gx_geterror();

	if(!gx_unrefhandle(&anprHandle))
		return gx_geterror();

	delete motdet;


	if(anprResult) 
	{
		// Plate found
		//printf ("\n findfirst  plate in %s , result is  <s> ",img_filename,anprresult->text);
		// Frees the result
		if(!gx_globalfree(anprResult))
		return gx_geterror();
	} 
	else 
	{
		// No plate
#ifdef _DEBUG
		printf ("\n find first plate in %s , result is <s> ",image,"NOT FOUND");
#endif
	}

Is my code correct for free allocated memory ? Is there a way to fix at a constant value (a parameter value) the allocating size that ANPR reallocate depending on images ?

Another question is it a exemple to how use the function cmd_format() because the information is not very clear ?

Thank you

Kenzo
ddddyyyy
Posts: 1
Joined: Tue Jun 09, 2009 6:22 am

Post by ddddyyyy »

Post Reply