WASHINGTON — One man told an officer during a Minnesota traffic stop that he was a licensed gun owner, and that he was reaching for his wallet, a witness said. The other was on the ground with police officers on top of him in Louisiana when someone shouted “He has a gun!”

Police in each circumstance thought the black man carrying a gun was dangerous and immediately shot him dead. Activists say black gun owners are often treated differently than white gun owners to a sometimes fatal degree.

The perception of an armed black person has not changed much since the days of slave rebellions, said the Rev. Kenn Blanchard, a former firearms instructor who runs BlackManWithAGun.com.

“If you have a firearm or you scare the wrong people, you’re going to get shot. You’re going to get killed. The perception of the scary black man still exists. The threat of the slave going rogue, it’s still there. The bad gangbanger,” Blanchard said.

Snipers opened fire on police officers in the heart of Dallas, Thursday evening, killing five officers and injuring six others during protests over two recent fatal police shootings of black men, according to police.

The gunfire broke while hundreds of people were gathered to protest fatal police shootings this week in Baton Rouge, Louisiana, and suburban St. Paul, Minnesota.

Police wrongly identified a black gun owner among the protesters as one of the shooters. The Dallas Police Department put out a photo on its Twitter account late Thursday of a man wearing a camouflage shirt and holding a rifle with the message: “This is one of our suspects. Please help us find him!” The tweet remained on the account early Friday morning.

The man in the photo, Mark Hughes, told Dallas TV station KTVT that he “flagged down a police officer” immediately after finding out he was a suspect. He said police lied during a 30-minute interrogation, telling him they had video of him shooting.

Videos posted online show Hughes walking around peacefully during the shooting and later turning over his gun to a police officer.

Protests were also held in several other cities across the country after a Minnesota officer on Wednesday fatally shot Philando Castile while he was in a car with a woman and a child. The aftermath of the shooting was livestreamed in a widely shared Facebook video. A day earlier, Alton Sterling was shot in Louisiana after being pinned to the pavement by two white officers. That, too, was captured on a cellphone video.

Castile’s girlfriend, Diamond Reynolds, said he told the officer during a traffic stop that he was carrying a gun for which he was licensed. Castile did “nothing but what the police officer asked of us, which was to put your hands in the air and get your license and registration,” she said.

On a video purporting to show the aftermath, the officer tells her: “I told him not to reach for it. I told him to get his hand out.”

“You shot four bullets into him, sir. He was just getting his license and registration, sir,” the woman responds.

The National Rifle Association, the nation’s largest gun rights organization, on Twitter called the Minnesota situation “troubling” and said it “must be thoroughly investigated.” The organization said it would not comment during the ongoing investigation, but “rest assured, the NRA will have more to say once all the facts are known.”

This all comes during a discussion in the United States about the killing of black men and women by police officers after the deaths of Travyon Martin in Florida, Michael Brown in Ferguson, Missouri, and Freddy Gray in Baltimore. Their deaths have inspired nationwide protests under the “Black Lives Matter” moniker including protests this week over the deaths of Castile and Sterling.

“Would this have happened if those passengers would have been white? I don’t think it would have,” Minnesota Gov. Mark Dayton said.

“We have seen tragedies like this too many times,” President Barack Obama said Thursday. When incidents like this occur, many Americans feel it’s because they’re not being treated the same, Obama said. “That hurts.”

It can be dangerous for black men and women to own guns in this policing environment, and it shouldn’t be, considering that gun ownership is a constitutional right, said Philip Smith, president and founder of National African American Gun Association.

Sterling was a convicted felon, which would have barred him from legally carrying a gun, according to court records. It was not immediately known whether the gun held by Castile was legal.

That information might not have mattered during their confrontations with police, Smith said.

“They’re not getting any kind of the benefit of the doubt. There’s no conversation. If there is a conversation, it’s a one-way conversation where the African-American male is being yelled at, pretty much, ‘Sit down and be quiet or you’re going to get shot,’ ” Smith said.

The first gun-control laws were passed to keep weapons out of the hands of black slaves and freedmen in colonial days, said Nicholas J. Johnson, a Fordham University law professor and author of “Negroes and The Gun: The Black Tradition of Arms.” During the post-Civil War period and the times of slavery, Southern states imposed strict gun laws against blacks that lasted through the civil rights movement.

Police have an outsized fear of armed blacks, activists said. The majority of blacks are not armed and the majority of killers of police officers are white. The FBI said 199 law enforcement officers were killed between 2011 and 2014. Of their killers, 133 were white and 70 were black.

Blacks also are only about half as likely as whites to have a firearm in their home — 41 percent vs. 19 percent — according to a 2014 Pew Research Center survey.

But another Pew survey showed more and more blacks becoming comfortable with owning guns, with 54 percent saying in 2014 that gun ownership does more to protect people than endanger personal safety, nearly double the 29 percent from December 2012.

“Historically, African-Americans have viewed guns kind of like the boogeyman — ‘The master told you not to look at the gun and we shouldn’t touch a gun,'” Smith said. “But that mindset is changing very, very quickly.”