Try this and see if you can adapt it to your problem.
In[1]:= g=Graphics[{Red, Rectangle[{5,10},{20,30}], Black, Polygon[{{8,15},{10,18},{18,22},{17,21}}]}]
Out[1]= <snip>
In[2]:= pixels = ImageData[g];
In[3]:= Dimensions[pixels]
Out[3]= {432, 328, 3}
In[4]:= p = Partition[Flatten[pixels], 3];
In[5]:= Count[RandomSample[p, 10^4], {0., 0., 0.}]/10^4 // N
Out[5]= 0.026
RandomSample chooses distinct points so the 10^4 must be less than the number of pixels in your image.
{0.,0.,0.} is "pure black" and if you are processing a captured image you may need to adjust that threshold to get all you accept as black.
Try this repeatedly on constructed images where you can manually verify that the result is approximately correct before depending on this.
If you look at this, which attempts to have half red and half black pixels and which finds a list of {color,number of pixels} for each color from ImageData,
In[6]:= g=Graphics[{Red,Rectangle[{5,10},{20,30}],Black,Polygon[{{5,10},{20,10},{20,20},{5,20}}]}];
pixels = ImageData[g];
p = Partition[Flatten[pixels], 3];
Count[RandomSample[p, 10^4], {0., 0., 0.}]/10^4 // N
Map[{#, Count[p, #]} &, Union[p]]
Out[7]= 0.4619
Out[8]= {{{0.,0.,0.}, 65208}, {{0.12549,0.,0.}, 418}, {{0.74902,0.74902,0.74902}, 312}, {{0.780392,0.780392,0.780392}, 2}, {{1.,0.,0.}, 65626}, {{1.,1.,1.}, 10130}}
it finds 65208 black pixels and 65626 red pixels, but also finds a small number of other colors and 10130 white pixels, so ImageData appears to be actually including more than just the contents of that colored rectangle and you should be careful using this.